Bladescope Posted April 13, 2009 Share Posted April 13, 2009 Afternoon again PHPFreaks, i've been wondering if it's possible to select multiple rows (with different names and values) from different tables. I'm trying to create a "Latest Additions" script which shows the latest 5 additions. In a perfect world, the query would take the first 5 results, ordered by date (which all tables have) from the 4 tables. Now the names themselves are close, three are called "Title" while one is called "Name", so there's not really any reason to why I can't rename the odd one out to follow suit. Server version: 5.0.45 Any help would be greatly appreciated! -Sean Link to comment https://forums.phpfreaks.com/topic/153874-solved-mysql-query-selecting-multiple-rows-from-different-tables/ Share on other sites More sharing options...
Mchl Posted April 13, 2009 Share Posted April 13, 2009 Read about UNION http://dev.mysql.com/doc/refman/5.0/en/union.html I think we even have a tutorial for that on www.phpfreaks.com Link to comment https://forums.phpfreaks.com/topic/153874-solved-mysql-query-selecting-multiple-rows-from-different-tables/#findComment-808704 Share on other sites More sharing options...
Maq Posted April 13, 2009 Share Posted April 13, 2009 I'm trying to create a "Latest Additions" script which shows the latest 5 additions. In a perfect world, the query would take the first 5 results, ordered by date (which all tables have) from the 4 tables. You're going to have to use LEFT JOIN and ORDER BY date DESC to obtain the correct order. Now the names themselves are close, three are called "Title" while one is called "Name", Should not be a problem. When you JOIN tables you need to specify what table each column comes from anyway. But you can ALIAS table names to make things a lot easier. Good luck. Link to comment https://forums.phpfreaks.com/topic/153874-solved-mysql-query-selecting-multiple-rows-from-different-tables/#findComment-808707 Share on other sites More sharing options...
Bladescope Posted April 13, 2009 Author Share Posted April 13, 2009 Fantastic, Thanks for the help Link to comment https://forums.phpfreaks.com/topic/153874-solved-mysql-query-selecting-multiple-rows-from-different-tables/#findComment-808709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.