I read a lot of threads about getting only the first line of the left join, but for some reason this does not work for me.
Here is my structure (simplified, of course)
Channels
id | title | content ---------------------- 1 | Feed 1 | ...
Painters
artist_id | artist_name ----------------------- 1 | Artist 1 2 | Artist 2
feeds_artists
rel_id | artist_id | feed_id ---------------------------- 1 | 1 | 1 2 | 2 | 1 ...
Now I want to get articles and join only the first artist, and I thought of something like this:
SELECT * FROM feeds LEFT JOIN feeds_artists ON wp_feeds.id = ( SELECT feeds_artists.feed_id FROM feeds_artists WHERE feeds_artists.feed_id = feeds.id LIMIT 1 ) WHERE feeds.id = '13815'
to get only the first line of feeds_artists, but that already doesn't work.
I cannot use TOP because of my database, and I cannot group the results by feeds_artists.artist_id , because I need to sort them by date (I got the results by grouping them this way, but the results are newest)
I tried something with OUTER APPLY, and also did not succeed. Honestly, I cannot imagine what is happening in these ranks - perhaps the biggest reason why I cannot get this to work.
DECISION:
SELECT * FROM feeds f LEFT JOIN artists a ON a.artist_id = ( SELECT artist_id FROM feeds_artists fa WHERE fa.feed_id = f.id LIMIT 1 ) WHERE f.id = '13815'
join mysql left-join groupwise-maximum
KddC Mar 25 '13 at 23:06 2013-03-25 23:06
source share