Basic queries Flashcards
query data in columns c1 and c2 from table t
SELECT c1, c2 FROM t;
Query all data from a table
SELECT * FROM t;
query data and filter rows with a condition
SELECT c1, c2 FROM t
WHERE condition;
Sort result set in ascending or descending order
SELECT c1, c2 FROM t
ORDER BY c1 ACS [DESC];
query distinct rows from a tale
SELECT DISTINCT c1, c2 FROM t
query how many rows are in a table
SELECT COUNT(*) FROM t
find number of rows in a certain value of c1
SELECT c1, COUNT(*) FROM t
GROUP BY c1;
find the total number of c1
SELECT SUM(c1) FROM t;
find total number c2 of every c1 type of data
SELECT c1, SUM(c2) FROM t
GROUP BY c1;
find the largest or smallest value in column c2
SELECT MAX(c2) [MIN(c2)] FROM t
query the names of the most downloaded apps in each category
SELECT name, category, MAX(downloads)
FROM fake_apps
GROUP BY category;
get the average value in column c1
SELECT AVG(c1) FROM t;