Using ORDER BY with three tables in DESC

I am trying to run this query

SELECT * FROM a JOIN b ON a.aid = b.bid JOIN c ON b.bid = c.cid WHERE a.subject LIKE "games" ORDER BY a.aid DESC;

It’s not returning any results or any error messages, so I guess with the lack of error messages I am kind of on the right vein, but it’s the lack of result(s) that is making something not work properly

I’ve actually have solved what I wanted to do. Solution down below

SELECT * FROM a JOIN keyword ON a.aid = b.bid JOIN c ON b.bid = c.cid WHERE a.subject LIKE 'games' ORDER BY a.dateTime DESC

Glad you got it worked out, but a couple comments

  1. SELECT * is almost NEVER a good idea. Specifying the fields you actually want is always more efficient and appropriate.
  2. using a.subject LIKE ‘game’ will return the same results as a.subject = ‘game’.

I see what you mean there, but considering that there are joined tables i.e. multiple tables, the list would be dreadfully long in what I am doing, there are 21 columns to deal with, this is done over three tables. I had no option

Depends on your point of view. How many columns are in all three tables? 30? 40? 50? And how many rows are being returned? Depending on the types of fields being returned, you may run into memory issues.

21 in all three of them

Only one row per subject being returned because it’s down to the dateTime column and there is no “for” or “while” loop involved in the script

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.