-
SQL 기초 문법 정리카테고리 없음 2023. 10. 21. 14:47
SQL 문법 플레이그라운드 링크:
https://www.w3schools.com/mysql/trymysql.asp?filename=trysql_select_all
MySQL Tryit Editor v1.0
WebSQL stores a Database locally, on the user's computer. Each user gets their own Database object. WebSQL is supported in Chrome, Safari, and Opera. If you use another browser you will still be able to use our Try SQL Editor, but a different version, usin
www.w3schools.com
기본 문법은 아래와 같고, 복잡한 쿼리들은 대부분 아래에서 파생되어서 사용되는 것 같다.
select 컬럼명 from 테이블명 where 조건정렬 조건 추가
select 컬럼명 from 테이블명 order by 정렬기준컬럼 asc -- 오름차순 (default) select 컬럼명 from 테이블명 order by 정렬기준컬럼 desc -- 내림차순산출될 데이터의 갯수 제한 (페이지네이션 등에서 쓰임)
select 컬럼명 from 테이블명 limit 시작, 갯수 -- (시작이 없으면 0 이 default)컬럼명 변경하여 출력
select 기존컬럼명 as '새로운컬럼명' from 테이블명 where 조건 -- 새로운 컬럼명은 단순히 출력 이름만 바꾸는 것이므로, where 등에 쓰이는 이름은 기존 컬럼명을 그대로 사용해야 함아래는 응용 예시
select * from Customers; select CustomerName from Customers; select * from Orders where EmployeeId = 3; select * from OrderDetails where Quantity < 5; select * from Customers order by ContactName; select * from OrderDetails order by ProductID asc, Quantity desc; select * from OrderDetails limit 10; select * from OrderDetails limit 0, 10; select * from OrderDetails limit 30, 10; select CustomerId as ID, CustomerName as '고객명', Address as '주소' from Customers; select CustomerId as '아이디', CustomerName as '고객명', City as '도시', Country as '국가' from Customers where Country = 'Germany' or City = 'London' order by CustomerName limit 0, 5;