0

I have the following query which is executed for a single user:

SELECT b1.id, b1.id_type, b1.id_team,
extra_bets_types.description, teams.conference, teams.division
FROM extra_bets b1
INNER JOIN teams ON b1.id_team = teams.id
INNER JOIN extra_bets_types ON b1.id_type = extra_bets_types.id
WHERE b1.id_user = ?
AND b1.id_season = 6
AND b1.id_type = 13
ORDER BY b1.timestamp DESC
LIMIT 2

It retrieves the 2 most recent rows from the table extra_bets for this specific user.

Now I need a similar query that retrieves this information for each id_user in a table called users_season.

I've tried using LIMIT 2 in a sub query (SELECT or INNER JOIN) but apparently this is not supported by MySQL.

I'm not that experienced in MySQL queries and kind of don't know what else to try here. What you suggest?

Thanks!

Sharpion
  • 55
  • 2
  • 9
  • See https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query – Strawberry Aug 06 '18 at 06:50

1 Answers1

-1

Have you tried something like this? Alternative to using LIMIT keyword in a SubQuery in MYSQL

Mysql does have the support to do LIMIT within a sub query, it is just picky in how it is used.

Hikari
  • 29
  • 1
  • I don't know how many rows I'll get as a result because the number of users is variable. Putting the LIMIT outside the subquery is not a viable option in this specific query. – Sharpion Aug 06 '18 at 13:38