如何在php上获得正确的sql值
如何在php上从此表中获取正确的sql值 我有两张桌子在下面如何在php上获得正确的sql值,php,mysql,sql,Php,Mysql,Sql,如何在php上从此表中获取正确的sql值 我有两张桌子在下面 Table: A StateID StudentID Attendee --------------------------------- ITB001 10 John ITB001 20 Bob ITB001 40 Mickey ITB001 60 Jenny ITB001 30 Ja
Table: A
StateID StudentID Attendee
---------------------------------
ITB001 10 John
ITB001 20 Bob
ITB001 40 Mickey
ITB001 60 Jenny
ITB001 30 James
ITB001 70 Erica
Table: B
StateID StudentID Attendee
---------------------------------
ITB001 10 John
ITB001 30 James
我想从表A中选择并输出与会者值,其中为减去表B。如果表B中的与会者有值John和James,则将列出表A中的与会者值,并且仅输出表A中没有John和James的值。因此,最终输出将是:
StateID StudentID Attendee
---------------------------------
ITB001 20 Bob
ITB001 40 Mickey
ITB001 60 Jenny
ITB001 70 Erica
任何帮助和提示都将不胜感激。谢谢。您可以通过以下方式完成此操作:
Select * from A where StudentID not in (select StudentID from B where 1=1)
如果我理解正确,您需要表A中尚未包含在表B中的所有内容。这可以使用左联接:
SELECT A.*
FROM A
LEFT JOIN B
ON A.StudentID = b.StudentID
AND A.StateID = b.StateID
WHERE B.StudentID IS NULL;
[outer]左联接允许从左操作数查询完整记录集,从右操作数查询部分记录集
SELECT A.*
FROM A
LEFT JOIN B
ON A.StudentID = b.StudentID
AND A.StateID = b.StateID
WHERE B.StudentID IS NULL;