MySQL

My personal cheatsheet/reference.

SELECT DISTINCT Album, Artist, Year FROM tableone ORDER BY Artist, Year 

SELECT * FROM tablename;

SELECT columnname FROM tablename;

SELECT columnname, columnname FROM tablename;

SELECT * FROM practice WHERE id BETWEEN 120 and 130

SELECT * FROM practice WHERE fieldone = 'Black Sabbath'

SELECT * FROM practice WHERE fieldone LIKE '%Zep%'

SELECT * FROM practice WHERE id < '100'

SELECT * FROM practice WHERE fieldone LIKE 'A____'

SELECT * FROM practice WHERE fieldone LIKE "Coldplay" OR fieldone LIKE "Cream"

SELECT * FROM practice WHERE fieldone IN ('Coldplay', 'Cream')

SELECT * FROM practice WHERE fieldone NOT IN ('AC-DC', 'Black Sabbath')

SELECT DISTINCT fieldone FROM practice

SELECT * FROM tablename ORDER BY columnname

SELECT * FROM tablename ORDER BY columnname DESC

SELECT * FROM tablename  LIMIT 0, 20

SELECT * FROM tablename ORDER BY columnname LIMIT 0, 20

SELECT * FROM tablename ORDER BY columnname DESC LIMIT 0, 20

SELECT COUNT(*) from tablename

SELECT DISTINCT columnname FROM tablename

SELECT fieldone, COUNT(*) FROM practice GROUP BY fieldone

SELECT fieldone, COUNT(*) AS Entries FROM practice GROUP BY fieldone

SELECT fieldone, COUNT(*) AS 'My Fucking Entries' FROM practice GROUP BY fieldone

SELECT fieldone, COUNT(*) AS 'My Entries' FROM practice GROUP BY fieldone ORDER BY 'My Entries'

SELECT fieldone, COUNT(*) AS 'My Entries' FROM practice GROUP BY fieldone ORDER BY 'My Entries' DESC

SELECT DISTINCT Album, Artist, Year FROM tester ORDER BY Album

SELECT DISTINCT Album, COUNT(*) FROM tester GROUP BY Album

SELECT DISTINCT Album, COUNT(*) AS 'Number of Songs' FROM tester GROUP BY Album

SELECT DISTINCT Album, COUNT(*) AS 'Number of Songs', Artist FROM tester GROUP BY Album

SELECT DISTINCT Album, COUNT(*) AS 'Number of Songs', Artist, Year FROM tester GROUP BY Album ORDER BY 'Number of Songs'

SELECT DISTINCT Album, COUNT(*) AS 'Number of Songs', Artist, Year FROM tester GROUP BY Album ORDER BY Artist

SELECT DISTINCT Album, Artist, Year FROM tester GROUP BY Album ORDER BY Artist

SELECT DISTINCT Album, Artist, Year FROM tester ORDER BY Artist // displays by artist and then albums alphabetically

SELECT DISTINCT Album, Artist, Year FROM tester ORDER BY Artist, Year // orders first by artist and then by year

SELECT DISTINCT Album, Artist, Year FROM tester // this easier method does same as above 

SELECT * FROM tablename WHERE columnname LIKE '%$tag%'