Hi Friends
Can we rewrite sub-queries into simple select statements or with joins ?
Sub-queries in SQL
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Oct 15, 2012, 3:02 AM EDT
Select * from tbl1 where id in (select id from tbl2 where status='AC')
You can rewrite it as
select tbl1.* from tbl1
inner join tbl2 on tbl2.Id=tbl1.id
where tbl2.status='AC'
Nitesh KejriwalRank #253 · 9.9K reputationPosted Oct 15, 2012, 3:10 AM EDT
SubQuery
========
SELECT a.* FROM tb1 a WHERE a.col1 IN (SELECT b.col1 FROM tbl2 b)
Joins
====
SELECT a.*,b.* FROM
tbl1 a JOIN tbl2 b
ON a.col1=b.col1
With Joins, you can retrieve any columns of the joining tables, while with sub queries, this is not possible.