开发者

MYSQL where x in all

开发者 https://www.devze.com 2023-01-28 04:46 出处:网络
I am running a query like this SELECT .......WHERE column_name IN (1,2,3) How can I use the same query and say

I am running a query like this

SELECT .......  WHERE column_name IN (1,2,3)

How can I use the same query and say

SELECT ........WHERE column_name IN (*)

and selec开发者_如何学Ct all rows?

Edit: The reason I need to do this is because of a bad database design and bad coding in general, for now I need to hack it. If I don't pass the query 1,2,3 .. I need to pass it something so it will return me all records. Is there a way to do it without changing the query? If you don't think this is possible then you should say that it is not possible in your answer.


Just remove the WHERE clause alltogether.


If you absolutely must have the WHERE clause, you could say:

WHERE 1

Or if you need to do the column_name IN bit, you could do something like:

SELECT .......  WHERE column_name IN (1,2,3) OR 1


... IN (SELECT DISTINCT column_name FROM table) ...


If you are trying to filter your return table base on values in another table:

select column_1, column_2 from table_1 where column_1 IN (select column_with_value from tabl_2)

0

精彩评论

暂无评论...
验证码 换一张
取 消