我们假设该表有ID(1,2,3,4,5)。我想用一个选择语句拉出1,4,5。我该怎么办?
Select m.Member_ID,m.Member_Name,r.Title from Member m,Record r
where m.Member_ID=r.Member_ID
and m.Member_ID=79
我想提取多个ID而不是79.
答案 0 :(得分:1)
最简单的方法是使用IN()
Select m.Member_ID,m.Member_Name,r.Title from Member m,Record r
where m.Member_ID=r.Member_ID
and m.Member_ID IN(1,4,5)
虽然您也可以在WHERE子句中单独列出。只需确保将它们包装在括号中以确保操作员正确行事。
Select m.Member_ID,m.Member_Name,r.Title from Member m,Record r
where m.Member_ID=r.Member_ID
and (m.Member_ID=1 OR m.Member_ID=4 OR m.Member_ID=5)
答案 1 :(得分:0)
您应该使用in
声明。但是,您应该学习正确的,明确的join
语法:
Select m.Member_ID, m.Member_Name, r.Title
from Member m join
Record r
on m.Member_ID = r.Member_ID
where m.Member_ID in (1, 4, 5);