PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am using subquery in left join to get data from both tables. Obviously I am doing something wrong that I am not getting value of "table2.mobile". Plz help to sort out the issue here...
SELECT t1.id,t1.startDate,t1.endDate,t2.mobile
FROM table1 t1
LEFT JOIN (SELECT id,mobile FROM table2 ORDER BY dateAdded DESC LIMIT 1) as t2
ON t1.Id = t2.Id
ORDER BY t1.startDate DESC
what you're trying to do? The query how you wrote it would select all rows from table1 and add some information from table 2 to a single row of result (that row matching the join condition). I would imagine you wanted a correlated subquery in the select clause instead:
SELECT t1.id,t1.startDate,t1.endDate,(select mobile FROM table2 t2 where t1.id=t2.id ORDER BY dateAdded DESC LIMIT 1) as mobile
FROM table1 t1
ORDER BY t1.startDate DESC