jeudi 26 novembre 2015

Get row values of matching columns sqlite

am trying to achieve the below result in sqlite.

table1

id   msg_send_by  msg_send_to            msg          log_dt
1        a            b                 test1       18/11/2015
2        c            b                 test2       20/11/2015
3        b            a                 test3       19/11/2015
4        b            c                 test4       21/11/2015

Input 18/11/2015

Result:
1   a   b   test1   test3   18/11/2015  19/11/2015
2   c   b   test2   test4   20/11/2015  21/11/2015

I tried this query but not sure how to put in one row like the expected above result

select * from (
    select * from tbl_msg_history where msg_send_by!='Millennials4' and log_dt like '%18/11/2015%'
    and msg like '@Millennials4%' and media='4CCCC5C5-EF59-4ED6-98B3-6B2DAB19CBD4'

    union

 select  * from (  select * from tbl_msg_history where msg_send_to in(
        select msg_send_by from tbl_msg_history where msg_send_by!='Millennials4' and log_dt like '%18/11/2015%'
        and msg like '@Millennials4%' ) and media='070EE88E-D7B6-454B-A299-F0715A25346E' ) 
) as t1 

 order by datetime(t1.log_dt)

Please provide ideas.. Thanks!!

Aucun commentaire:

Enregistrer un commentaire