开发者

Need help to create a join Mysql

开发者 https://www.devze.com 2022-12-21 04:16 出处:网络
I have 2 tables Table 1 IDStatus 1D 2F 3D Table 2 SID IDApprove 11N 21Y 31Y 42Y I need a query to joins 2 tables on ID and finds records that don not have N in their Approve column.Does anyo

I have 2 tables

Table 1

ID  Status
1   D
2   F
3   D

Table 2


SID ID  Approve
1   1   N
2   1   Y
3   1   Y
4   2   Y

I need a query to joins 2 tables on ID and finds records that don not have N in their Approve column. Does anyone have any开发者_JAVA百科 clue how to implement this?


SELECT * FROM Table1 AS t1 
INNER JOIN Table2 AS t2 
ON t2.id = t1.id 
WHERE t2.Approve != 'N' 


SELECT DISTINCT t1.id,t1.status,t2.approve FROM Table1 AS t1 
INNER JOIN Table2 AS t2 
ON t2.id = t1.id 
WHERE t2.Approve != 'N'

you can't have the t2.sid in the select clause though as it will void the DISTINCT criteria.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号