SELECT * FROM Products;
원하는 테블에서 특정 컬럼만 출력하고 싶을 경우
SELECT ProductName, Price FROM Products;
SELECT [ProductName], [Price] FROM Products;
DISTINCT는 중복값을 제거
SELECT DISTINCT Price FROM Products;
개행을 해도 되지만 마지막 세미콜론을 잊지 말자!
SELECT * FROM Products ORDER BY ProductID DESC;
SELECT *
FROM Products
ORDER BY ProductID DESC;
SELECT Price AS 가격 FROM Products;
산술연산도 가능하고
컬럼끼리의 연산도 가능함
SELECT Price*0.8 AS 할인된가격 FROM Products;
SELECT Price + Vat FROM Products;
Products 테이블에서 ProductCode 중 111로 시작하고 국가가 한국인것을 SELECT
SELECT * FROM Products
WHERE ProductCode LIKE '111%'
AND Country = 'Korea';
Products 테이블에서 ProductCode 중 111로 시작하고 국가가 한국이거나 중국인것을 SELECT
SELECT * FROM Products
WHERE ProductCode LIKE '111%'
AND (Country = 'Korea' OR Country = 'China');
Products 테이블에서 ProductCode 중 111로 시작하고 국가가 한국이거나 중국인것을 제외하고 SELECT
SELECT * FROM Products
WHERE ProductCode LIKE '111%'
AND NOT (Country = 'Korea' OR Country = 'China');
10000원에서 30000사이의 가격을 가진 물건의 이름을 SELECT
SELECT ProductName FROM Products
WHERE Price BETWEEN 10000 AND 30000;
괄호 안 값과 일치하는 값을 SELECT
SELECT ProductName FROM Products
WHERE Price IN (19900, 9900);
콘X 라는 productName을 가진 제품을 SELECT
SELECT * FROM Products
WHERE ProductName LIKE '콘_';
콘으로 시작하는 productName을 가진 제품을 SELECT
SELECT * FROM Products
WHERE ProductName LIKE '콘%';
가격이 NULL 값을 갖는 것을 SELECT
SELECT * FROM Products
WHERE Price IS NULL;
10000원 이상의 제품만 SELECT
SELECT * FROM Products
WHERE Price > 10000;