SELECT
id,
name,
age,
gender
FROM users
WHERE
WHERE
구문을 사용하여 검색SELECT
id,
name,
age,
gender
FROM users
WHERE name = "아이유"
INSERT INTO users (
id,
name,
age,
gender
) VALUES (
1,
"아이유",
27,
"여자"
), (
2,
"제인",
19,
"여자"
)
UPDATE users SET age = 25 WHERE name = "아이유"
DELETE FROM users WHERE gender = "남자"
SELECT 1
FROM users
WHERE EXISTS (SELECT *
FROM users
WHERE user_name = '아이유');
SELECT lname, fname
FROM customer
WHERE NOT EXISTS (SELECT *
FROM orders
WHERE customers.customer_id = orders.c_id);
CREATE TABLE accounts(
id INT NOT NULL AUTO_INCREMENT,
account_type VARCHAR(100) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE users(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
hashed_password VARCHAR(255) NOT NULL,
account_id INT NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY email (email),
CONSTRAINT `users_account_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`)
);
join
구문을 사용함SELECT
테이블별칭.조회할칼럼,
테이블별칭.조회할칼럼
FROM 기준테이블 별칭
INNER JOIN 조인테이블 별칭 ON 기준테이블별칭.기준키 = 조인테이블별칭.기준키
SELECT
users.id,
users.name,
users.age,
users.gender,
accounts.account_type
FROM users
JOIN accounts ON accounts.id = users.account_id