MYSQL join two tables and list oldest entry -


i have 2 tables data select. helpdesk system , collects information ticket activity.

table #1  ticket_id   log_type        entry_date      1       ticket_created   1471442825    1       ticket_closed    1471442825    2       ticket_created   1438035457    2       ticket_closed    1438035269    3       ticket_created   1438034956    3       ticket_closed    1438034121    table #2  ticket_id   customer_name   status     1          bill          open    2          john          closed    3          mark          canncelled 

what

ticket_id   customer_name     log_type      entry_date     1           bill         ticket_created  1471442825    2           john         ticket_created  1471442825    3           mark         ticket_created  1471442825 

where oldest entry_date 5 days or more (to list outdated tickets).

i have tried several joins didn’t succeed.

you can use join min(entry_date), e.g.:

select t2.ticket_id, t2.customer_name, t1.log_type, t1.date table_2 t2, join (select ticket_id, min(entry_date) `date` table_1 group ticket_id) t1 on t2.ticket_id = t1.ticket_id , t2.entry_date = t1.date; 

to filter out records, can add condition on t1.date date_add function.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -