SELECT

- 모든 데이터 가져오기

SELECT * FROM dbo.Employee

 

- 특정 열의 데이터 가져오기

SELECT EmpID, HireDate, Email 
FROM dbo.Employee 
GO

 

-특정 행의 데이터만 가져오기

SELECT * 
FROM dbo.Employee 
WHERE EmpID = 'S0005' 
GO

 

- 특정 열의 특정 행만 가져오기

SELECT EmpID, EmpName, HireDate, EMail 
FROM dbo.Employee 
WHERE EmpID = 'S0005' 
GO

 

- 비교 연산자 사용

SELECT EmpID, EmpName, HireDate, EMail
FROM dbo.Employee 
WHERE Salary >= 8000

SELECT EmpID, EmpName, HireDate, EMail 
FROM dbo.Employee 
WHERE HireDate < '2007-01-01'

 

- 문자열 비교

SELECT EmpID, EmpName, HireDate, Email 
FROM dbo.Employee 
WHERE EmpName = '홍길동'

SELECT EmpID, EmpName, HireDate, Email 
FROM dbo.Employee 
WHERE EmpName LIKE '김%'

 

- 논리 연산자 사용

SELECT EmpID, EmpName, HireDate, EMail 
FROM dbo.Employee 
WHERE HireDate >= '2008-01-01' AND Salary >= 6000

SELECT EmpID, EmpName, HireDate, EMail 
FROM dbo.Employee 
WHERE HireDate >= '2008-01-01' OR Salary >= 6000

SELECT EmpID, EmpName, HireDate, EMail 
FROM dbo.Employee 
WHERE HireDate >= '2008-01-01' AND NOT Salary >= 6000

 

- 범위 조건 지정

SELECT EmpID, EmpName, HireDate, EMail 
FROM dbo.Employee 
WHERE Salary BETWEEN 6000 AND 8000

SELECT EmpID, EmpName, HireDate, EMail 
FROM dbo.Employee 
WHERE Salary >=6000 AND Salary <= 8000

 

- 리스트 조건 지정

SELECT EmpID, EmpName, HireDate, EMail 
FROM dbo.Employee 
WHERE DeptID IN ('SYS', 'MKT', 'HRD')

SELECT EmpID, EmpName, HireDate, EMail 
FROM dbo.Employee 
WHERE DeptID = 'SYS' OR DeptID = 'MKT' OR DeptID = 'HRD'

 

 

 

 

'MSSQL 2008 > SQL' 카테고리의 다른 글

UPDATE 기본 문법  (0) 2014.03.03
INSERT 기본 문법  (0) 2014.03.03
DB에서 컬럼 이름 찾기 - MS SQL  (0) 2014.02.26
SQL Server 에서 GO의 의미 (Batch)  (0) 2014.01.20
SET 옵션들  (0) 2014.01.13
by 짱구를꼭말려 2014. 3. 3. 14:42