I have a table “articles” that has a column “company” which has list of companies or an article type – crappy I know, but it’s not my DB. 🙂 Let’s say there are n articles for each type. I need to select the first article (based on year, or any other criteria) that is of the type. Something like this:
select * from details where (company = 'aaa' or company = 'bbb' or ...)
I know what the types are, so they can be hardcoded. I need to limit only the first article for each type. Thanks!
EDIT
given the sample data:
id company copy issue ------------------------ 1 apple 'abc' NULL 2 bmw 'abc' NULL 3 ibm 'abc' NULL 4 news 'abc' 2 5 news 'abc' 3 6 seagate 'abc' NULL 7 events 'abc' 1 8 features 'abc' 5 9 samsung 'abc' NULL
I need rows 4, 7, 8.
EDIT2
Sorry if I wasn’t clear. Essentially the table contains two different types of data. One is company info, and one is article info. Basically I need to do this:
select * from articles where company = "news" order by issue limit 1;
select * from articles where company = "events" order by issue limit 1;
select * from articles where company = "features" order by issue limit 1;
but with a single query.
Something like this perhaps
Example here – http://sqlfiddle.com/#!2/bb8f2/6