Basic queries Flashcards Preview

SQL > Basic queries > Flashcards

Flashcards in Basic queries Deck (12)
Loading flashcards...
1

query data in columns c1 and c2 from table t

SELECT c1, c2 FROM t;

2

Query all data from a table

SELECT * FROM t;

3

query data and filter rows with a condition

SELECT c1, c2 FROM t
WHERE condition;

4

Sort result set in ascending or descending order

SELECT c1, c2 FROM t
ORDER BY c1 ACS [DESC];

5

query distinct rows from a tale

SELECT DISTINCT c1, c2 FROM t

6

query how many rows are in a table

SELECT COUNT(*) FROM t

7

find number of rows in a certain value of c1

SELECT c1, COUNT(*) FROM t
GROUP BY c1;

8

find the total number of c1

SELECT SUM(c1) FROM t;

9

find total number c2 of every c1 type of data

SELECT c1, SUM(c2) FROM t
GROUP BY c1;

10

find the largest or smallest value in column c2

SELECT MAX(c2) [MIN(c2)] FROM t

11

query the names of the most downloaded apps in each category

SELECT name, category, MAX(downloads)
FROM fake_apps
GROUP BY category;

12

get the average value in column c1

SELECT AVG(c1) FROM t;