Some Tips and Tricks in Sql

Prabhukiran345
Posted by Prabhukiran345 under Sql Server category on | Points: 40 | Views : 620
Tip 1:Our sql query becomes faster if we use the actual columns names in SELECT statement instead of than '*'.
Exaple:Write the query as
SELECT id, first_name, last_name, age, subject FROM student_details;

Instead of
SELECT * FROM student_details;

Tip 2:Do not use HAVING clause for any other purposes.Because HAVING clause is used to filter the rows after all the rows are selected. It is just like a filter.
Exaple:Write the query as
SELECT subject, count(subject) 
FROM student_details
WHERE subject != 'Science'
AND subject != 'Maths'
GROUP BY subject;

Instead of
SELECT subject, count(subject) 
FROM student_details
GROUP BY subject
HAVING subject!= 'Science' AND subject!= 'Maths';

Comments or Responses

Login to post response