08-10-2006, 03:28 PM
Wad Up, i'm brand new to mysql/php but have limped by using dreamweaver. I got an issue. I'm displaying personnel actions data in a details page based on the ID of the personnel action record, but would like to display a value (Employee Name) from a related table (tblemployees) based on a payroll_num field in the details page. These two fields are related, payroll_num and payrollID(primary in tblemployees). How do I add both tables in my query or is this the right way to get this accomplished?
Need major help:eek:
08-10-2006, 04:53 PM
You need to use a JOIN. Do a Google on MySQL JOIN or something similar to get more in-depth tutorials, but the general idea for what it sounds like you want to do is:
table1 AS t1
table2 AS t2
t1.relatedcolumn = t2.relatedcolumn
t1.idcolumn = x
That will only return rows where both tables have matching values in their related columns. If you need to return all rows of table1 whether they have a matching table2 value or not, use a LEFT JOIN instead of INNER. A good tutorial will have more info.
08-10-2006, 09:39 PM
Thanks KC for the reply, I'll follow your advice. If anyone else has some insight, its appreciated. This is a great forum!:D