SQL Flashcards

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/123

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

124 Terms

1
New cards

Keyword to retrieve data

SELECT

2
New cards

Clause that specifies table(s) to query

FROM

3
New cards

Clause to filter rows

WHERE

4
New cards

Clause to sort results

ORDER BY ASC|DESC

5
New cards

Keyword to remove duplicate rows

DISTINCT

6
New cards

Limit number of rows returned (MySQL/Postgres)

LIMIT

7
New cards

Wildcard operator for pattern matching

LIKE

8
New cards

Operator to test range inclusively

BETWEEN AND

9
New cards

Operator to test membership in list

IN (val1, val2, …)

10
New cards

Predicate to test missing values

IS NULL / IS NOT NULL

11
New cards

Syntax to alias a column

SELECT column AS alias

12
New cards

Concatenate two conditions AND / OR

WHERE cond1 AND cond2

13
New cards

Negate a condition

NOT condition

14
New cards

Return only unique combinations of columns

SELECT DISTINCT col1, col2

15
New cards

Select all columns

SELECT *

16
New cards

Retrieve current date in SQL Standard

CURRENT_DATE

17
New cards

Retrieve number of rows in result

COUNT(*)

18
New cards

Arithmetic operator for integer division in SQL Server

/

19
New cards

Concatenate strings in Postgres

||

20
New cards

Function to convert string to upper case

UPPER(string)

21
New cards

Aggregate function to sum numeric column

SUM(column)

22
New cards

Aggregate function to calculate average

AVG(column)

23
New cards

Find minimum value in column

MIN(column)

24
New cards

Find maximum value in column

MAX(column)

25
New cards

Group rows that share same values

GROUP BY column

26
New cards

Filter groups after aggregation

HAVING condition

27
New cards

Count non-NULL values

COUNT(column)

28
New cards

Count distinct values in column

COUNT(DISTINCT column)

29
New cards

Alias aggregate results

SELECT AVG(price) AS avg_price

30
New cards

Place HAVING clause

After GROUP BY, before ORDER BY

31
New cards

Join returning matching rows in both tables

INNER JOIN

32
New cards

Join returning all left table rows plus matches

LEFT (OUTER) JOIN

33
New cards

Join returning all right table rows plus matches

RIGHT (OUTER) JOIN

34
New cards

Join returning all rows from both, NULL when no match

FULL (OUTER) JOIN

35
New cards

Join that pairs every row of two tables

CROSS JOIN

36
New cards

Keyword to specify join condition

ON

37
New cards

Join using columns with same name automatically

NATURAL JOIN

38
New cards

Self‑join aliasing same table twice

SELECT … FROM table t1 JOIN table t2 ON …

39
New cards

Using clause when join columns share name

USING (column)

40
New cards

Difference between INNER and LEFT JOIN

LEFT keeps unmatched left rows, INNER drops them

41
New cards

Combine results eliminating duplicates

UNION

42
New cards

Combine results keeping duplicates

UNION ALL

43
New cards

Return rows common to both result sets

INTERSECT

44
New cards

Return rows in first result not in second

EXCEPT (Postgres) / MINUS (Oracle)

45
New cards

Requirement for set ops columns

Same number and compatible data types

46
New cards

Subquery in SELECT list

Scalar subquery

47
New cards

Subquery in FROM clause

Derived table / inline view

48
New cards

Subquery depending on outer query

Correlated subquery

49
New cards

Check existence of rows in subquery

EXISTS (subquery)

50
New cards

Syntax to compare value to all from subquery

value > ALL (subquery)

51
New cards

Create a new table

CREATE TABLE table_name (…);

52
New cards

Primary key constraint

PRIMARY KEY (column)

53
New cards

Auto‑increment integer column MySQL

INT AUTO_INCREMENT PRIMARY KEY

54
New cards

Ensure column cannot be NULL

NOT NULL

55
New cards

Ensure unique values in column

UNIQUE (column)

56
New cards

Referential link to another table

FOREIGN KEY (col) REFERENCES ref_table(col)

57
New cards

Default value for column

DEFAULT

58
New cards

Add a column to existing table

ALTER TABLE table_name ADD column datatype;

59
New cards

Modify data type of column

ALTER TABLE tablename ALTER COLUMN col TYPE newtype;

60
New cards

Remove a table

DROP TABLE table_name;

61
New cards

Rename a table (Postgres)

ALTER TABLE oldname RENAME TO newname;

62
New cards

Create table from select results

CREATE TABLE new AS SELECT …;

63
New cards

Truncate table data quickly

TRUNCATE TABLE table_name;

64
New cards

Variable‑length character data

VARCHAR(n)

65
New cards

Fixed‑length character data

CHAR(n)

66
New cards

Integer data type standard

INT or INTEGER

67
New cards

Exact numeric with scale and precision

DECIMAL(p,s)

68
New cards

Date without time

DATE

69
New cards

Timestamp with time zone Postgres

TIMESTAMPTZ

70
New cards

Boolean literals in SQL

TRUE / FALSE

71
New cards

Binary large object in MySQL

BLOB

72
New cards

UUID type purpose

Store unique identifiers

73
New cards

Insert new row

INSERT INTO table (columns) VALUES (values);

74
New cards

Insert from another table

INSERT INTO table SELECT …;

75
New cards

Update existing rows

UPDATE table SET column=value WHERE condition;

76
New cards

Delete rows

DELETE FROM table WHERE condition;

77
New cards

Copy table structure only

CREATE TABLE new LIKE existing;

78
New cards

Upsert in Postgres

INSERT … ON CONFLICT (key) DO UPDATE

79
New cards

Merge command standard SQL

MERGE INTO target USING source ON condition WHEN MATCHED THEN UPDATE SET … WHEN NOT MATCHED THEN INSERT …;

80
New cards

Return generated keys after insert (MySQL)

INSERT … RETURNING id; (Postgres)

81
New cards

Start a transaction

BEGIN; or START TRANSACTION;

82
New cards

Save changes in transaction

COMMIT;

83
New cards

Undo uncommitted changes

ROLLBACK;

84
New cards

Savepoint purpose

Partial rollback marker within transaction

85
New cards

Set transaction isolation level

SET TRANSACTION ISOLATION LEVEL ;

86
New cards

Default isolation in Postgres

Read Committed

87
New cards

Create an index on column

CREATE INDEX idx_name ON table(column);

88
New cards

Unique index ensures

No duplicate values in indexed column(s)

89
New cards

Remove an index

DROP INDEX idx_name;

90
New cards

Composite index

Index on multiple columns

91
New cards

B‑tree index suited for

Equality and range queries

92
New cards

Create a view

CREATE VIEW view_name AS SELECT …;

93
New cards

Drop a view

DROP VIEW view_name;

94
New cards

Temporary result named in WITH clause

Common Table Expression (CTE)

95
New cards

Recursive CTE keyword

WITH RECURSIVE

96
New cards

Materialized view difference

Stores data physically, needs refresh

97
New cards

Syntax to define window frame

OVER (PARTITION BY … ORDER BY …)

98
New cards

Assign sequential number to rows

ROW_NUMBER() OVER (…)

99
New cards

Rank with gaps for ties

RANK() OVER (…)

100
New cards

Aggregate without collapsing rows

SUM(column) OVER (…)