Do we need nested queries in the SQL?

India
September 20, 2012 9:55am CST
Hi, Most of the SQL programmers use nested queries as they are quite easy to learn. But implementation wise they are quite in-efficient. I tried to change some of the nested queries to simple queries. I succed in all cases. So my question is do we really need nested queries?
3 responses
@owlwings (39593)
• Cambridge, England
20 Sep 12
There are two discussions here on why and when sub-queries may be necessary and useful in SQL: http://www.sqlserverclub.com/articles/solving-complex-query-calculations-using-nested-queries.aspx http://beginner-sql-tutorial.com/sql-subquery.htm
• India
26 Sep 12
Hi, I have gone through both the links. These are nice tutorials for those who are begineers in query nesting. But they rarely talks about "Why and when subqueries may be necessary?" Although these links talks about "Nested queries can provide an extremely elegant method for solving complex problems." But this is not true for expert programmer as non-nested queries are more efficient in many situations. For example read the following discussion :- http://weblogs.sqlteam.com/jeffs/archive/2007/07/12/the-nested-where-in-sql-anti-pattern.aspx
@deeno985 (37)
• Malaysia
20 Sep 12
Yes nested queries is needed. No queries no SQL.
• India
20 Sep 12
What do you mean by "No query no SQL". I am focussing on nesting, I am not discarding importance of Queries.
• Philippines
15 Feb 13
It really depends on the occasion. But as a programmer, I must say that nested queries are really needed especially with complex table-relationship. It is inefficient if we cut the queries into smaller and simpler one to make it look easy but it is not. It will make the work slower and probably erroneous fetched data.