我需要通过它的ID在1个查询中选择几行,例如这里是我写的东西
SELECT * FROM posts WHERE post_id = "15 , 14 , 14"
如何在真正的SQL查询中完成?
答案 0 :(得分:8)
SELECT * FROM posts WHERE post_id IN (14,15);
答案 1 :(得分:5)
SELECT * FROM posts WHERE post_id IN ( "15" , "14" )
答案 2 :(得分:1)
最快的选择,效率更高:
SELECT * FROM posts WHERE post_id IN (14,15)
但是使用说明OR
并没有错误
SELECT * FROM posts WHERE post_id = 14 OR post_id = 15
答案 3 :(得分:0)
在where condition中使用OR / AND。像:
SELECT * FROM posts WHERE post_id = '13' OR post_id = '14' OR post_id = '15'
答案 4 :(得分:0)
你也可以使用:
SELECT * FROM posts WHERE post_id BETWEEN 14 and 15