WHERE | GROUP BY / \ HAVING ORDER BY \ / LIMIT
When we issue a SELECT command we are shown the results in the order that the records were entered.
We can change this by using the 'GROUP BY' directive, allowing us to display the data grouped by field. To return the results ordered by artist:
mysql> SELECT * FROM cds
-> GROUP BY cds.artist;
The HAVING condition is really just another WHERE condition that acts as a 'secondary constraint' on the result set. This works best when you are trying to apply a restrictive condition after a grouping has taken place.
SELECT T1.ID FROM TEST_MULTIPLE T1 WHERE T1.TITLE IN (SELECT T2.TITLE FROM TEST_MULTIPLE T2 GROUP BY T2.TITLE HAVING COUNT(T2.TITLE) > 1)
Insert multiple rows into a table in single insert query -
INSERT INTO customers(cust_name,
'Pep E. LaPew',
'100 Main Street',
'42 Galaxy Way',