Basic SQL Syntax Flashcards
Learn the syntax of basic SQL commands.
ALTER TABLE
ALTER TABLE table_name
ADD column_name datatype;
AND
SELECT column_name(s) FROM table_name WHERE column_1 = value_1 AND column_2 = value_2;
AS
SELECT column_name AS ‘Alias’
FROM table_name;
AVG()
SELECT AVG(column_name) FROM table_name;
BETWEEN
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value_1 AND value_2;
CASE
SELECT column_name, CASE WHEN condition THEN 'Result_1' WHEN condition THEN 'Result_2' ELSE 'Result_3' END FROM table_name;
COUNT()
SELECT COUNT(column_name) FROM table_name;
CREATE TABLE
CREATE TABLE table_name ( column_1 datatype, column_2 datatype, column_3 datatype );
DELETE
DELETE FROM table_name
WHERE some_column = some_value;
GROUP BY
SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name;
HAVING
SELECT column_name, COUNT()
FROM table_name
GROUP BY column_name
HAVING COUNT() > value;
INNER JOIN
SELECT column_name(s)
FROM table_1
JOIN table_2
ON table_1.column_name = table_2.column_name;
INSERT
INSERT INTO table_name (column_1, column_2, column_3)
VALUES (value_1, ‘value_2’, value_3);
IS NULL and IS NOT NULL
SELECT column_name(s)
FROM table_name
WHERE column_name IS NULL;
LIKE
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;