Sql Tips and tricke

Posted by Prabhukiran345 under Sql Server category on | Points: 40 | Views : 1156
SQL Tip 1:Use JOIN instead of subqueries. As a programmer, subqueries are something that we can be tempted to use and abuse.
Subqueries, as show below, can be very useful:
SELECT a.id, 
(SELECT MAX(created)
FROM posts
WHERE author_id = a.id)
AS latest_post FROM authors a

SQL Tip 2:Prune SELECT lists. Every column that is SELECTed consumes resources for processing. There are several areas that can be examined to determine if column selection is really necessary.
WHERE (COL8 = ‘X’)

Comments or Responses

Login to post response