Quick brief: Just now I currently get a list of results by using the below code. I am trying to group my u_feed
results by c_feed
id
's.
$uid = '15';
SELECT u.uid, u.fid, f.url,f.icon, u.title, f.favicon, f.domain FROM u_feed u INNER JOIN feed f ON f.id = u.fid WHERE u.uid = '$uid'
I have just added a table called c_feed
which will hold the name
and uid
of each category. The u_feed
table will then use the column cid
to check c_feed
for the id
.
table c_feed
table feed
table u_feed
I tried SELECT u.uid, u.fid, f.url, f.icon, u.title, f.favicon, f.domain, c.cname FROM u_feed u INNER JOIN feed f ON f.id = u.fid INNER JOIN c_feed c ON c.id = u.cid WHERE u.uid = '15' LIMIT 0 , 30
This only returned
But it should have 11 rows (image below without grouping)
It is your inner join
which only include the record if there is an associated record in c_feed. So the only records you got back were the two WITH a cid
.
You might be looking for left join
s.
SELECT u.uid, u.fid, f.url, f.icon, u.title, f.favicon, f.domain, c.cname
FROM u_feed u
LEFT JOIN feed f ON f.id = u.fid
LEFT JOIN c_feed c ON c.id = u.cid
WHERE u.uid = '15' LIMIT 0 , 30
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.