[英]Select multiple tuples based on hard coded values SQL Query Help
I want to use a select statement to grab specific tuples based on their ID. 我想使用select语句根据其ID获取特定元组。 So I want to be able to grab col1 from table1 where id = 1,5,9,15 in one query if thats possible.
所以我希望能够在一个查询中从table1中获取col1,其中id = 1,5,9,15,如果可能的话。 How might I go about doing this?
我该怎么做呢?
Select col1 from table1 where id = 1 and id = 5...
I tried this, but I couldn't get anything. 我尝试过这个,但我什么也得不到。 What am I missing?
我错过了什么?
Thanks! 谢谢!
In a single row, the id can't be both 1 and 5 at the same time. 在单行中,id不能同时为1和5。 That's impossible, so the query will never match any row.
这是不可能的,因此查询永远不会匹配任何行。
It can be 1 or 5, though. 但它可以是1 或 5。
SELECT col1 FROM table1 WHERE id = 1 OR id = 5 ...
You can also use the IN syntax: 您还可以使用IN语法:
SELECT col1 FROM table1 WHERE id IN (1, 5, 9, 15)
您想要使用OR而不是AND。
Select col1 from table1 where id = 1 or id = 5...
使用in
:
select col1 from table1 where id in (1, 5, 9, 15);
grab col1 from table1 where id = 1,5,9,15
从table1中获取col1,其中id = 1,5,9,15
You want tables IN 1,5,9,15, not =. 你想要表IN 1,5,9,15,而不是=。
WHERE id IN (1,5,9,15)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.