본문 바로가기
Study/SQL

Select_02 기초공부

by v-ni 2022. 3. 21.

5. Select TOP, LIMIT and ROWNUM

-> 반환할 레코드 수를 지정하는 데 사용

참고 : SQL Server는 Select TOP  |  MySQL은 LIMIT  | Oracle은 ROWNUM

 

 

Select TOP 3 * From Customers; (SQL Server)

Select TOP 3 * From Customers;

 

Select * From Customers LIMIT 3; (MySQL  LIMIT 절)

 

Select * From Customers LIMIT 3;

 

 

 

Select * From Customers Where ROWNUM <= 3;(Oracle ROWNUM)

 

Select * From Customers Where ROWNUM <= 3;

 

 

 

6. Set 

-> update와 함께 사용해 테이블에서 업데이트해야 하는 열과 값을 지정

 

참고 : Update문의 Where절에 유의!!! Where절은 없데이트해야 하는 레코드를 지정한다. 
Where 절을 생략하면 테이블의 모든 레코드가 업데이트 된다.

 

1)  Update Customers SET ContactName = 'Alfred Schmidt', City = 'Frankfurt' Where CustomerID = 1;

-> CustomersID = 1 을 새 ContactName 및 새 도시로 업데이트

 

Update Customers SET ContactName = 'Alfred Schmidt', City = 'Frankfurt' Where CustomerID = 1;

 

 

2) Update Customers SET ContactName = 'Juan' Where Country = 'Mexico';

->국가가 "Mexico"인 모든 레코드에 대해 "CustactName"필드를 "Juan"으로 업데이트

 

Update Customers SET ContactName = 'Juan' Where Country = 'Mexico';