MySQL manually adds id to the "WHERE IN (SELECT ...)" section

I have this query:

SELECT * from t1 WHERE child_id IN (SELECT child_id from t2 WHERE parent_id='1234') OR parent_id='1234' 

Is it possible to do something like this:

 SELECT * from t1 WHERE child_id IN ( (SELECT child_id from t2 WHERE parent_id='1234') UNION '5678' ) 

The UNION keyword gives an error message, and I tried to do a google search, but it's hard to find something while searching for "Mysql concat IN"

Hope my question is clear.

+4
source share
2 answers

Yes, like this:

 SELECT * from t1 WHERE child_id IN ( SELECT child_id from t2 WHERE parent_id='1234' UNION SELECT 5678 ) 
+3
source

The requests are different (I mean the example and the one who has the error), but you can do:

 SELECT * from t1 WHERE child_id IN (SELECT child_id from t2 WHERE parent_id='1234' union all select '5678' ); 
+1
source

Source: https://habr.com/ru/post/1500519/


All Articles