I want to left join this query but it does not seem to work
select *,(SELECT datediff(t1.expirydate,CURDATE())as daysleft
from tbl1 t1,
left join tbl2 t2 on (t1.mid=t2.mid and t1.pid=t2.pid and t1.uid=3)
you have an error in your SQL syntax;
right syntax to use near 'left join tbl2 t2 on (t1.mid=t2.mid and t1.pid=t2.p' at line 3
Please let me know where am i wrong
here am joining 3 table but doesnt work
SELECT t1.*, t2.*,t3.* datediff(t1.expirydate, CURDATE()) AS daysleft FROM tbl1 t1 left join
tbl2 t2 on t1.mid = t2.mid and t1.pid = t2.pid left join tbl3 t3 on t3.pid = t2.pid where t1.uid=3
for knw 3 table but the i get syntax error
You don't put a comma between joins.
SELECT t1.*, t2.*, datediff(fsp.expirydate, CURDATE()) AS daysleft
FROM tbl1 t1
left join tbl2 t2 on t1.mid = t2.mid and t1.pid = t2.pid
cross join fsp
where t1.uid = 3
You also shouldn't put the t1.uid = 3
condition in the ON
clause. ON
should only contain conditions that relate the two tables, and in the case of LEFT JOIN
it can also include conditions on the table you're joining with ( t2
in this case).
No comma after "t1" on line 2.
Also I don't think you can do "*," on line 1, you need to either do "SELECT *" or "SELECT column, column2"
You have Used Comma (,) before Left Join It's not correct Synatx
Try this
select t1.*,(SELECT datediff(fsp.expirydate,CURDATE())as daysleft
from tbl1 t1
left join tbl2 t2 on (t1.mid=t2.mid and t1.pid=t2.pid and t1.uid=3)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.