我在SQL语句中使用where in子句,如下所示
select * from user_image where product_id in =product_idproduct_id是另一条sql语句的结果值,如下所示
select product_id from products ORDER BY views DESC因为我们不能在内部select语句中使用order by,所以我尝试这样做。但这里的问题是product_id的结果集是这样的1,2,5,3,7,2,其中我需要这样的(1,2,5,3,7,2),这样in语句就可以执行了。
我使用的DataBase是mysql。
请在这方面给我提个建议。
发布于 2015-03-16 16:04:27
联接或子查询
加入
select i.* from user_image as i inner join products as p on i.product_id = p.product_id;子查询
select * from user_image where product_id in (select product_id from products)https://stackoverflow.com/questions/29071947
复制相似问题