mysql 联合查询
做join时不会强制要求必须通过主键进行连接,比如如下两个表:CREATE TABLE ajoin ( id int(11) NOT NULL, pname varchar(32) DEFAULT NULL, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8CREATE TABLE bjoin ( tid int(11) NOT NULL, sname varchar(32) DEFAULT NULL, PRIMARY KEY (tid)) ENGINE=InnoDB DEFAULT CHARSET=utf8通过如下的非主键进行连接是OK的SELECT R.id,R.pname FROM ajoin R LEFT JOIN bjoin M on M.sname = R.pname WHERE ( R.id IN ('1','2','3') )
赞0
踩0