如何在sql

时间:2016-02-28 10:02:39

标签: mysql sql

如何在sql中执行if和join语句,如:

if (t1.street != ' ' and t2.street != ' ')
select * from table1 t1 inner join table2 t2 on t1.street = t2.street.

sqlfiddle

我想要的只是在街道上加入!=' '

谢谢!

2 个答案:

答案 0 :(得分:1)

http://sqlfiddle.com/#!9/de1be/2/0

select * from table1 t1 
inner join table2 t2 on t1.street = t2.street AND (t1.street != ' ' and t2.street != ' ')

将条件添加到联接

答案 1 :(得分:1)

您可以在where条件下执行此操作。

SELECT      *
FROM        table1 t1 
INNER JOIN  table2 t2 on t1.street = t2.street
WHERE       t1.Street != ''

http://sqlfiddle.com/#!9/6ce8f/3

不需要检查t2.Street是否!=''因为t1.Street == t2.Street