Results 1 to 2 of 2
Feb 18, 2010, 15:04 #1
include column from one table in another result set
I have two tables:
tblRentalUnits - this table consists of numerous fields with one in particular called iRentID. This contains an integer value that maps to another table that contains a column called sName that contains the human readable name of the community in which this rental resides.
tblCommunities - contains numerous fields, with it's ID (unique) that is referenced to from tblRentalUnits.
Basically what I'm looking to do is select ALL the rental units (from tblRentalUntis), but also include/add the community name (from the ID linkage - iRentID as stored in tblCommunities). This will then allow me to sort by community alphabetically.
I've looked at doing join's etc, but I'm not so savy in mySQL to achieve this with one select statement.
Any help would be greatly appreciated.
After some tinkering I found this kinda works:
SELECT * FROM tblRentalUnits INNER JOIN tblCommunities ON tblRentalUnits.iRentID = tblCommunities.ID;
However, now I have all columns from both tables (which makes sense based on the JOIN) in one result set, however I JUST want the sName column from tblCommunities and all the others from tblRentalUnits
Okay so after even more tinkering I found that this looks like it should work. Does anyone see why it wouldn't?
SELECT ru.*, c.sName AS sCommName FROM tblRentalUnits AS ru, tblCommunities AS c WHERE ru.iRentID = c.id;