카테고리 없음
데이터베이스(database) ALTER, FORIGEN KEY(외래키), JOIN
Nekisse_lee
2018. 7. 24. 15:43
JOIN
이 순서대로 만들어야한다.
1. stu
2. prof
3. class
4. sugang
ex) 제일어려운 sugang테이블의 예
create table sugang(
cid int(11)
sid int(11) primary key(cid,uid),
foreign key(sid) references stu(id),
foreign key(cid) references class(cid)
)
UNION을 사용
--full outer join (outer join)
SELECT * FROM stu
LEFT JOIN prof
ON stu.pid = prof.pid
UNION
SELECT * FROM stu
RIGHT JOIN prof
ON stu.pid = prof.pid;