skip to Main Content

I have some values in my table like this,

Main Table

I want to select only those with the latest/highest date,
The result will be like the picture in below:

Result Table

I already try with union but it didn’t meet my expectations

2

Answers


  1. Chosen as BEST ANSWER

    I got the query to make the result like that

    this my SQL query :

    SELECT table1.jobno AS 'Job. No',

    (SELECT CONCAT(search_date_1, ' - ', last_search_by_1) FROM table1 WHERE id IN (SELECT MAX(id) FROM table1 WHERE jobno = table1.jobno AND search_by_1 != '')) AS 'Search Option 1',

    (SELECT CONCAT(search_date_2, ' - ', search_by_2) FROM table1 WHERE id IN (SELECT MAX(id) FROM table1 WHERE jobno = table1.jobno AND search_by_2 != '')) AS 'Search Option 2',

    (SELECT CONCAT(search_date_3, ' - ', search_by_3) FROM table1 WHERE id IN (SELECT MAX(id) FROM table1 WHERE jobno = table1.jobno AND search_by_3 != '')) AS 'Search Option 3'

    FROM table1 AS table1

    GROUP BY table1.jobno


  2. Halo bro..

    SELECT *
    FROM your_table
    WHERE search_date_1 = (SELECT MAX(search_date_1) FROM your_table)
    AND search_date_2 = (SELECT MAX(search_date_2) FROM your_table)
    AND search_date_3 = (SELECT MAX(search_date_3) FROM your_table)
    

    Please test this code, if it is correct please accept the answer.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search