I have 3 mysql tables (order , camp , user) as bellow values,
order_table
ID camp_id orderDate message
1 1 2015-01-01 ok
2 1 2015-02-01 ok
3 2 2015-03-01 not ok
4 3 2015-01-01 not ok
5 1 2015-04-01 not ok
6 2 2015-01-01 ok
7 3 2015-07-01 not ok
camp_table
camp_id camp_uid camp name
1 10 first camp
2 11 second camp
3 12 third camp
4 10 forth camp
user_table
uid uname
10 abc
11 xyz
12 wrt
i want to have result as bellow
uname,camp name,message
for last 2 records of each user from order_table for today order by orderDate
I want to join these tables to have uname from user_table and camp name from camp_table and message from order_table. for today order by orderDate Thanks
Select
ct.camp_name,
ut.uname,
ot.message FROM order_table as ot
LEFT JOIN camp_table as ct on ot.camp_id = ct.camp_id
LEFT JOIN user_table as ut on ct.camp_uid = ut.uid
order by ot.id desc
limit 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With