mysql - How to create a subquery -


how can combine 2 mysql statement 1 statement.

these statements

mysql 1

select et.imei imei, max(from_unixtime(et.timestamp)) tid exp_terminal_log et group et.imei order tid desc; 

mysql 1 output

imei              latest date 351895053434419   2013-04-28 11:12:28 354851057203265   2013-04-28 11:10:44 354851057234989   2013-04-28 11:10:32 

mysql 2

select ct.title title, t.phoneid imei transactions t inner join exp_channel_titles ct on (ct.entry_id = t.restaurant_id) t.cardid != '88888888' , t.cardid > 0 , ct.status= 'open' group ct.entry_id  

mysql 2 output

title       imei café katz   351895053434419 restaurant1 354851057203265 restaurant2 354851057234989 

desired output

title       imei               latest date café katz   351895053434419    2013-04-28 11:12:28 restaurant1 354851057203265    2013-04-28 11:10:44 restaurant2 354851057234989    2013-04-28 11:10:32 

this how tried, not work, because of subquery returning more 1 row.

select et.imei imei, max(from_unixtime(et.timestamp)) tid exp_terminal_log et group et.imei having et.imei = (  select t.phoneid imei transactions t inner join exp_channel_titles ct on (ct.entry_id = t.restaurant_id) t.cardid != '88888888' , t.cardid > 0 , ct.status= 'open' group ct.entry_id ) 

try this:

select    ct.title title,    t.phoneid imei,   t2.tid transactions t inner join exp_channel_titles ct on ct.entry_id = t.restaurant_id inner join (   select et.imei imei, max(from_unixtime(et.timestamp)) tid   exp_terminal_log et   group et.imei ) t2 on t.phoneid = t2.imei t.cardid != '88888888'    , t.cardid > 0   , ct.status= 'open' group ct.entry_id;  

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -