SELECT * FROM 테이블명; -- *온 해당 테이블의 모든 데이터 열람을 의미
USE book_db;
select * from booklist;
show tables; -- db 내 생성된 테이블 조회하기

desc author; -- author 테이블의 구조를 설명
desc booklist; -- booklist 테이블의 구조를 설명
create table booklist(
id int(11) not null auto_increment,
title varchar(30) not null,
description text,
createdAt datetime not null,
author_id int(11) default null,
primary key(id));
create table author(
id int(11) not null auto_increment,
name varchar(20) not null,
profile varchar(200) default null,
primary key(id));
-- author 테이블에 데이터 입력하기
insert into author (id, name, profile) values (1, 'lee', 'developer');
insert into author (id, name, profile) values (2, 'kim', 'CEO');
insert into author (id, name, profile) values (3, 'park', 'data scientist');
-- booklist 테이블에 데이터 입력하기
insert into booklist (title, description, createdAt, author_id) values ('mySQL', 'mySQL is ...', now(), 1);
insert into booklist (title, description, createdAt, author_id) values ('C#', 'C# is ...', now(), 1);
insert into booklist (title, description, createdAt, author_id) values ('C++', 'C++ is ...', now(), 1);
insert into booklist (title, description, createdAt, author_id) values ('python', 'python is ...', now(), 3);
insert into booklist (title, description, createdAt, author_id) values ('Java', 'Java is ...', now(), 2);
select * from booklist where title = 'python';
결과값

select * from booklist limit 4;
select * from booklist order by id desc limit 2;
select title from booklist order by id desc limit 2;
결과값



select distinct author_id from booklist;
결과값
select * from booklist join author on booklist.author_id = author.id;
select booklist.id, title, description, createdAt, name, profile from booklist join author on booklist.author_id = author.id;
결과값

rename table booklist to booklist_backup;
소문자/대문자화 하기데이터, 시작 위치, 길이): 대상 데이터를 시작 위치로부터 길이만큼 잘르기데이터, 변경 데이터, 변경할 데이터): 대상 데이터에서 변경 데이터를 변경할 데이터로 대체select title, lower(title), upper(title) from booklist;
select title, substr(title, 1, 2) from booklist;
select createdAt, replace(createdAt, '2024', '2025') from booklist;
select 열이름 as 별칭 from 테이블이름;
select title as 제목 from booklist;
select description as 설명 from booklist;
select booklist.id as booklistId, title, description, createdAt, name, profile from booklist join author on booklist.author_id = author.id;
결과값
id → booklistId 로 변경됨
