0

Is it possible to create a nested select statement something like this in mysql?

SELECT * from myTable WHERE id = (SELECT id from data where dataId = 1);

If this is not the correct way to formulate such a statement could anyone point me in the right direction for the way in which it should be formulated.

Thanks

2 Answers 2

1
SELECT * from myTable WHERE id IN (SELECT id from data where dataId = 1);
                                ^---- You should use in rather than =
Sign up to request clarification or add additional context in comments.

Comments

0

This syntax is fine. Note though that this will only work if there is one data with dataId 1. If there is likely to be multiple ids returned by the inner select then it is better to use:

SELECT * from myTable WHERE id IN (SELECT id from data where dataId = 1);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.