mysql join with limit 1

Viewed 18191

Suppose I have two tables in one to many relationship.

And, I want to select columns from each main record along with the first record from a related table.

I tried some ways but it just doesn't go...

Here I end up with this SQL fiddle:

http://sqlfiddle.com/#!2/39fdb/3

The problem there is that it just cannot reference a.ID from a subselect.

This does not work, of course, but it's just all I could think of

select a.*,b.* from event a left join 
(select * from event_pictures where a.ID=article limit 1)
b on a.ID=b.article;

Any ideas on how to fix it?

4 Answers
Related