I’m screwing up this LEFT JOIN
Posted
by Jason Shultz
on Stack Overflow
See other posts from Stack Overflow
or by Jason Shultz
Published on 2010-05-24T23:45:25Z
Indexed on
2010/05/24
23:51 UTC
Read the original article
Hit count: 116
php
|codeigniter
I'm doing a left join on several tables. What I want to happen is that it list all the businesses. Then, it looks through the photos, videos, specials and categories. IF there are photos, then the tables shows yes, if there are videos, it shows yes in the table.
It does all that without any problems. Except for one thing. For every photo, it shows the business that many times. For example, if there are 5 photos in the DB for a business, it shows the business five times.
Obviously, this is not what I want to happen. Can you help?
function frontPageList() {
$this->db->select('b.id, b.busname, b.busowner, b.webaddress, p.thumb, v.title, c.catname');
$this->db->from ('business AS b');
$this->db->where('b.featured', '1');
$this->db->join('photos AS p', 'p.busid = b.id', 'left');
$this->db->join('video AS v', 'v.busid = b.id', 'left');
$this->db->join('specials AS s', 's.busid = b.id', 'left');
$this->db->join('category As c', 'b.category = c.id', 'left');
return $this->db->get();
© Stack Overflow or respective owner