W3schools - SQL_UNION / GROUP BY
이 페이지는 다음에 대한 공부 기록입니다
Lecture에서 배웠던 내용을 복습하며 작성했습니다
찾으시는 정보가 있으시다면
주제별reference를 이용하시거나
우측 상단에 있는 검색기능을 이용해주세요
UNION
Is used to combine the result-set two or more SELECT statements
Every SELECT statement within UNION must have same number of columns
The columns must also have similar data types
The columns in every SELECT statement must be also be in the same order
The column names in the result-set are usually equal to the column names in the first SELECT statement
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
-- UNION selects only distinct values by default. To allow duplicate values, use ALL
SELECT column_name(s) FROM table1
UNION ALL
SELECT column_name(s) FROM table2;
GROUP BY
Groups rows that have the same values into summary rows
Is often used with aggregate functions(like COUNT(), AVG(),..) to group the result-set by one or more columns
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
HAVING
Was added to SQL because the WHERE keyword cannot be used with aggregate functions
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY conlumn_name(s)
HAVING condition
ORDER BY column_name(s);