C
C
cybernoob2018-09-18 15:55:50
MySQL
cybernoob, 2018-09-18 15:55:50

How to make a subquery?

If we select only one field, and as a result of such a selection, IDs are formed, then we can do this:

SELECT `data`, `need`
FROM `tab2`
WHERE `id2` IN (SELECT `id1` FROM `tab1` WHERE...)

How to repeat the trick, provided that the inner query fetches more data:
SELECT `id1`, `data1`, `data2`
FROM `tab1` WHERE...

So in the selection, not only id1 but also data1, data2, is it possible to indicate inside IN that I am interested in id1 from the entire array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
ponaehal, 2018-09-18
@cybernoob

SELECT `data`, `need`
FROM `tab2`
WHERE `id2` IN (SELECT id1 FROM  (SELECT `id1`,field1,field2  FROM `tab1` WHERE...) t)

but the meaning of this action eludes me completely ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question