我有这种表结构:
Table Name: collisions
Fields: id, creator1, creator2
(1, 1, 2) - simple data in my sql table
Table Name: creators
Fields: id, artistname
(1, john smith)- simple data in my sql table
(2, steven michael)- simple data in my sql table
我需要加入这些表,这样我就可以获得艺术家姓名而不是 creator1 id 和 creator 2 id。
这是我到目前为止所做的:
$this->db->select('collisions.*, creators.artist_name AS cr1, creators.artist_name as cr2');
$this->db->join('creators', 'collisions.creator1 = cr1.id AND collisions.creator2 = cr2.id', 'left');
$data = $this->db->get('collisions')->result();
但我收到此错误:
Unknown column 'cr1.id' in 'on clause'
SELECT `collisions`.*, `creators`.`artist_name` AS cr1, `creators`.`artist_name` as cr2 FROM (`collisions`) LEFT JOIN `creators` ON `collisions`.`creator1` = `cr1`.`id` AND collisions.creator2 = cr2.id
有人可以告诉我我做错了什么吗?