SELECT news_store.id, news_store.title, news_store.message, news_store.date, news_store.time, news_store.file_name,
news_regions.title AS region, news_regions.path AS region_path,
news_categories.title AS category, news_categories.path AS category_path,
news_hosts.host AS host
FROM news_store, news_regions, news_categories, news_hosts
WHERE news_store.cat_id IN (1,3,6,9,11,13,17,44,51,54,76,88)
AND news_regions.id = news_store.geo_id
AND news_categories.id = news_store.cat_id
AND news_hosts.id = news_store.src_id
ORDER BY news_store.id DESC LIMIT 0, 3
Problem is that I need 3 records with 3 DIFFERENT news_store.src_id's, but when I try to put in code "GROUP BY news_store.src_id" after ORDER BY statement I have MySQL error, and if I put this code before ORDER BY I have incorrect result data, coz rows first grouped and only then sorted . Please, help, I'm going mad with this query...
You're not writing an aggregate query, so you can't group by a single column value, without telling the database how to aggregate all the other columns, or adding them also to your group by clause.
nyef, thanks!!! I've tried DISTINCT many times, but always got some errors, I've tried it now and all seems like working, may be I have made some errors in my previous queries, thanks!
Nope... It seems like working, but NOT. DISTINCT keyword is used to ALL fields, so if my row id is always different, MySQL think that rows are different even src_id is same, but I need exactly rows with different src_id...