jeudi 4 décembre 2014

Single SQL query to retrieve data in a particular order (not ASC/DESC)


I have a MySQL table, let's say called reviews review_id, product_id, language_id, rating, review, author language_id ranges from 1 to 10 for 10 different languages.


Let's say I determine that my visitor is browing the site using language whose id is 4


Is there a way to write a single query that: 1. First grabs the reviews for that product in current language 2. Next, grabs the reviews for that product in other languages sorted by language


So, basically does the job of the following 2 queries run one after the other:



SELECT * FROM reviews WHERE product_id = 723 AND language_id = 4;
SELECT * FROM reviews WHERE product_id = 723 AND language_id != 4 ORDER BY language_id ASC;




Aucun commentaire:

Enregistrer un commentaire