테이블에서 데이터를 조회
문법
1 2 3 4 5 | SELECT 칼럼명1, 칼럼명2 [ FROM 테이블명 ] [ GROUP BY 칼럼명] [ ORDER BY 칼럼명 [ ASC | DESC ]] [LIMIT offset, 조회 할 행의 수] |
예제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | DROP TABLE IF EXISTS `student`; CREATE TABLE `student` ( `id` tinyint(4) NOT NULL , ` name ` char (4) NOT NULL , `sex` enum( '남자' , '여자' ) NOT NULL , `address` varchar (50) NOT NULL , `birthday` datetime NOT NULL , PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `student` VALUES (2, '박재숙' , '남자' , '서울' , '1985-10-26 00:00:00' ); INSERT INTO `student` VALUES (1, '이숙경' , '여자' , '청주' , '1982-11-16 00:00:00' ); INSERT INTO `student` VALUES (3, '백태호' , '남자' , '경주' , '1989-2-10 00:00:00' ); INSERT INTO `student` VALUES (4, '김경훈' , '남자' , '제천' , '1979-11-4 00:00:00' ); INSERT INTO `student` VALUES (8, '김정인' , '남자' , '대전' , '1990-10-1 00:00:00' ); INSERT INTO `student` VALUES (6, '김경진' , '여자' , '제주' , '1985-1-1 00:00:00' ); INSERT INTO `student` VALUES (7, '박경호' , '남자' , '영동' , '1981-2-3 00:00:00' ); |
1 | SELECT * FROM student; |
1 | SELECT name , birthday FROM student; |
1 | SELECT * FROM student WHERE id=3; |
1 | SELECT * FROM student WHERE sex= '남자' AND address= '서울' ; |
1 | SELECT * FROM student WHERE sex= '여자' OR address= '서울' ; |
1 | SELECT * FROM student LIMIT 1; |
1 2 3 | SELECT * FROM student LIMIT 1,1; SELECT * FROM student LIMIT 2,1; SELECT * FROM student LIMIT 3,1; |
1 | SELECT * FROM student WHERE sex= '남자' LIMIT 2; |