728x90
반응형
SMALL
1. 조건절 - Where절
3-1. 특정 데이터 검색
- select 필드명1, 필드명2, ... from 테이블명 where 조건절
✅ word 테이블에서 레벨이 1인 데이터들만 검색해보자.
select * from word where lev=1;
✅ member 테이블에서 userid가 'apple'인 회원의 userid, username, hp, email 필드 조회하기
select userid, username, hp, email from member where userid='apple';
✅ member 테이블에서 성별이 남자인 사람의 userid, username 조회하기
💡 조건절에 없는 필드도 select절에 작성하여 조회할 수 있음
select userid, username from member where gender='male';
✅ point가 300이상인 회원 정보를 조회하기
select * from member where point >= 300;
✅ 조건절을 사용하여 로그인 Query 작성해보기
select from userid, username, hpm email from member where userid='apple' and userpw='1111;
# 비밀번호가 틀렸을 때
select userid, username, hp, email from member where userid='apple' and userpw='2222';
3-2. 특정 데이터 삭제
- delete table 테이블명 where 조건절: 조건절에 만족하는 데이터만 삭제
✅ 한글뜻이 '체리'인 데이터를 삭제해보자.
delete from word where kor='체리';
select * from word;
3-3. 특정 데이터 수정
- update 테이블명 set 필드명1=값1, 필드명2=값2, .... where 조건절
- where 절이 없으면 필드에 해당하는 값들이 일괄 변경됨
- Null 값의 변경
- update 테이블명 set 컬럼명1=값1,... where (컬럼명 is null)
✅ word테이블에서 lev 필드가 null값인 데이터를 1로 수정해보자.
update word set lev=1 where (lev is null);
select * from word;
728x90
반응형
LIST
'DataBase > MySQL' 카테고리의 다른 글
[MySQL] 필드 기준으로 그룹 하기, 그룹에 조건 달기 - GROUP BY, HAVING (0) | 2023.03.16 |
---|---|
[MySQL] 테이블에서 데이터 정렬하기 - ORDER BY절 (0) | 2023.03.16 |
[MySQL] SQL에서의 Null값을 알아보자! 🧐 (0) | 2023.03.16 |
[MySQL] 테이블 데이터 조회하기 - SELECT절, LIMIT (0) | 2023.03.16 |
[MySQL] SQL 연산자에 대해 알아보자! 🧐 (0) | 2023.03.16 |