Query to become broader if limited results

Hi everyone,

Am struggling to setup a query that can return additional results if the default query doesn’t return enough.

For example:

Table: Games

id
name
genre
console

Query:
Select * FROM [Games] WHERE genre=‘Driving’ and console=‘PlayStation’ LIMIT 0,5

If there are only 3 matching results, however, how could I adapt this query to show 2 results from other titles are in the same genre, but on any format?

E.g.

  • Result 1: Genre = Driving / Console = PlayStation
  • Result 2: Genre = Driving / Console = PlayStation
  • Result 3: Genre = Driving / Console = PlayStation
  • Result 4: Genre = Driving / Console = Any
  • Result 5: Genre = Driving / Console = Any

Ideally in a single query, really stuck on setting this up!

Often most results will have the full set of 5, but sometimes there are only 3/4 and ideally I’d want to fill up the gap!

Many thanks for any help!
J

first of all, i must warn you, stick to either SQL Server syntax (e.g. square brackets around identifier names) or MySQL syntax (e.g. LIMIT), because if you mix them, you’ll get errors

SELECT something , anything , just_please_god_not_the_dreaded_evil_select_star FROM Games WHERE genre='Driving' ORDER BY CASE WHEN console='PlayStation' THEN 'Humpty' ELSE 'Dumpty' END DESC LIMIT 0,5

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