sql - mysql query to three tables, want to use JOIN instead subquery -


i want use join instead subquery find trade id not exist on trade_log filtered ip , current date mysql syntax below.

select plug.id a,          plug.url b,          trade.id c     plug, trade    trade.id = plug.trade_id      , trade.id not in (select trade_log.trade_id                            trade_log                           trade_log.ip = '".$ip."'                             , trade_log.log_date = curdate())      , trade.status = 1         , plug.status = 1   order plug.weight desc      limit 1 

please me...

use:

   select p.id a,           p.url b,           t.id c      plug p      join trade t on t.id = p.trade_id                  , t.status = 1 left join trade_log tl on tl.trade_id = t.id                       , tl.ip = mysql_real_escape_string($ip)                       , tl.log_date = curdate()     p.status = 1       , tl.ip null  order p.weight desc     limit 1 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -