Fields from table CD:
ID int (10)
M_id int (10)
cd_name varchar (10)
Fields from table MEMBER:
ID int (10)
NAME varchar (5)
PHONE varchar (15)
MYSQL:
CREATE TABLE CD
(`ID` int, `M_id` int,`cd_name` varchar(10))
;
INSERT INTO CD
(`ID`, `M_id`,`cd_name`)
VALUES
(234, 1100,'再會夜都市'),
(235, 1101,'光陰')
;
CREATE TABLE Member
(`ID` int, `NAME` varchar(5), `PHONE` varchar(15))
;
INSERT INTO Member
(`ID`, `NAME`, `PHONE`)
VALUES
(1100, '陳一郎','0910411123'),
(1101, '李茂山','0950504524')
;
SQL語法:
select c.cd_name,
m.name,m.phone
from CD c
left join Member m
on c.m_id = m.id
結果:
CD_NAME | NAME | PHONE |
再會夜都市 | 陳一郎 | 0910411123 |
光陰 | 李茂山 | 0950504524 |
sqlfiddle.com/#!2/3cf37/1/0
全站熱搜
留言列表