如何在子句mysql中使用数字列表

时间:2015-03-16 07:54:58

标签: mysql sql database

我正在使用我的SQL语句中的where子句,就像这样

select * from user_image where product_id in =product_id

product_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)所以在声明中可以执行。

我使用的DataBase是mysql

请在此建议我。

1 个答案:

答案 0 :(得分:0)

加入或子查询

加入

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)