两张表,a和b,通过字段no相连,a表有字段void,如果void is null,该条记录已删除现在想找到a表中no号码是no1和no2的记录,但是如果其中有记录已经被删除了则不用找出来了怎么表达呢?
直接这样不行吗? select a.*,b.* from a left join b on a.no=b.no where a.no in('no1','no2') and a.void is not null;
select * from yyq_card1 A left join yyq_card2 B on a.SFID = b.SFID where b.SFID = 1 ------------------------------------------------------------------------------------- 1 yyq_address1 1 100 1 yyq_address1 1 -100 1 yyq_address1 1 111
select * from yyq_card1 A left join yyq_card2 B on a.SFID = b.SFID where (b.SFID = 1 or b.SFID = 2) and b.JE is not null ---------------------------------------------------------------------------------------------- 1 yyq_address1 1 100 1 yyq_address1 1 111 1 yyq_address1 1 -100 2 yyq_address2 2 200 --你的这样子行不? select * from a left join b on a.id = b.id where (a.no = no1 or a.no = no2) and a.void is not null
select a.*,b.* from a left join b on a.no=b.no where a.no in('no1','no2') and a.void is not null; 应用楼上的,where 肯定可以用在左连接中的
如果是连接条件的话,直接写在left join on xxx and xxx就可以了
请问11楼,where在left join里怎么用啊
select 显示列 from a left join b on a.no=b.no where a.no in(no1,no2)
因为要用到on,写where不行,建议嵌套子查询!
left join on a.id=b.id and on a.name=b.name and on...
可以这样写 select a.*,b.* from a left join b on a.no=b.no and a.no in('no1','no2') and a.void is not null 不需要where 条件 就可以了
select a.*,b.* from a left join b on a.no=b.no where a.no in('no1','no2') and a.void is not null;
select * from yyq_card1 A left join yyq_card2 B on a.SFID = b.SFID where b.SFID = 1
-------------------------------------------------------------------------------------
1 yyq_address1 1 100
1 yyq_address1 1 -100
1 yyq_address1 1 111
select * from yyq_card1 A left join yyq_card2 B on a.SFID = b.SFID where (b.SFID = 1 or b.SFID = 2) and b.JE is not null
----------------------------------------------------------------------------------------------
1 yyq_address1 1 100
1 yyq_address1 1 111
1 yyq_address1 1 -100
2 yyq_address2 2 200 --你的这样子行不?
select * from a left join b on a.id = b.id where (a.no = no1 or a.no = no2) and a.void is not null
应用楼上的,where 肯定可以用在左连接中的
可以这样写 select a.*,b.* from a left join b on a.no=b.no and a.no in('no1','no2') and a.void is not null 不需要where 条件 就可以了