MySQL subquery fetch only latest value from JOIN table

Ahmed

I have the following MySQL query. The user_extra table can return multiple values for a given user_id. I would like only the latest a.session_date value from user_extra.

SELECT DISTINCT (user_id) user_id, a.value  
 FROM user_reg ap 
 JOIN user_extra a USING (user_id) 
WHERE ap.session_date BETWEEN '2017-01-01' AND '2017-06-10' AND a.session_date<='2017-01-01'

Any ideas how I can do this?

D. Pareek
select ap.user_id, ap1.value
from user_reg ap
inner join (
    select user_id, max(session_date) as MaxDate, value
    from user_extra 
    group by user_id
) ap1 on ap.user_id = ap1.user_id and ap.date = ap1.MaxDate

It will give maximum session date for single user id.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MYSQL: select latest record only (on left join table)

From Dev

Join data table with latest value, if not found show null mysql?

From Dev

How to get latest value from table with self inner join

From Dev

MySQL SELECT latest record from a subquery with UNION

From Dev

Subquery or Join a table where a certain value is minimum

From Dev

MySQL join table only to find missing values from previous join

From Dev

MySQL join table only to find missing values from previous join

From Dev

MySQL Update Value from SubQuery

From Dev

mySQL Query - select join if latest record in join table contains a specific value

From Dev

Laravel 4 - Join table but only latest row

From Dev

Laravel 4 - Join table but only latest row

From Java

Unable to use single-valued column from subquery table join in HAVING clause with aggregate value

From Dev

mysql left join selecting only highest from left table

From Dev

MySQL JOIN - json returns data only from one table

From Dev

MySQL latest record from table

From Dev

Join table with a subquery result

From Dev

MySQL LEFT JOIN only one row, ordered by column without subquery

From Dev

MySQL LEFT JOIN only one row, ordered by column without subquery

From Dev

Fetch from mySQL to HTML TABLE

From Dev

MySQL Subquery with Averages From Another Table

From Dev

MySQL: Add a condition on a subquery from a joint table

From Dev

MySQL set column value from another table (JOIN 3 tables)

From Dev

How to select distinct max value from multiple join table MySQL

From Dev

MySQL subquery JOIN

From Dev

MySQL inner join on subquery

From Dev

MySQL Left Join Subquery with *

From Dev

SubQuery in INNER JOIN (MySQL)

From Dev

MySQL alternative to subquery/join

From Dev

Mysql JOIN subquery

Related Related

  1. 1

    MYSQL: select latest record only (on left join table)

  2. 2

    Join data table with latest value, if not found show null mysql?

  3. 3

    How to get latest value from table with self inner join

  4. 4

    MySQL SELECT latest record from a subquery with UNION

  5. 5

    Subquery or Join a table where a certain value is minimum

  6. 6

    MySQL join table only to find missing values from previous join

  7. 7

    MySQL join table only to find missing values from previous join

  8. 8

    MySQL Update Value from SubQuery

  9. 9

    mySQL Query - select join if latest record in join table contains a specific value

  10. 10

    Laravel 4 - Join table but only latest row

  11. 11

    Laravel 4 - Join table but only latest row

  12. 12

    Unable to use single-valued column from subquery table join in HAVING clause with aggregate value

  13. 13

    mysql left join selecting only highest from left table

  14. 14

    MySQL JOIN - json returns data only from one table

  15. 15

    MySQL latest record from table

  16. 16

    Join table with a subquery result

  17. 17

    MySQL LEFT JOIN only one row, ordered by column without subquery

  18. 18

    MySQL LEFT JOIN only one row, ordered by column without subquery

  19. 19

    Fetch from mySQL to HTML TABLE

  20. 20

    MySQL Subquery with Averages From Another Table

  21. 21

    MySQL: Add a condition on a subquery from a joint table

  22. 22

    MySQL set column value from another table (JOIN 3 tables)

  23. 23

    How to select distinct max value from multiple join table MySQL

  24. 24

    MySQL subquery JOIN

  25. 25

    MySQL inner join on subquery

  26. 26

    MySQL Left Join Subquery with *

  27. 27

    SubQuery in INNER JOIN (MySQL)

  28. 28

    MySQL alternative to subquery/join

  29. 29

    Mysql JOIN subquery

HotTag

Archive