tags:

views:

39

answers:

3

Using MySQL I need to return new first/last name columns for each user in table1.

**Table1**  
uid  
1  
2  

**Table2**  
id   fid   uid   field_value  
1    1     1     Joe  
2    2     1     Blow  
3    1     2     Joe  
4    2     2     Blogs

**Result**
uid   first_name   last_name
1     Joe          Blow
2     Joe          Blogs
A: 

assuming you have columns first_name, and last_name in table2:

select uid, first_name, last_name from table1 left join table2 on table1.uid=table2.uid
Sander
+2  A: 

The solution is simple,

select t1.uid, t21.field_value first_name, t22.field_value last_name
from table1 t1, table2 t21, table2 t22
where t1.uid=t21.uid and t1.uid=t22.uid and t21.fid=1 and t22.fid=2
culebrón
Thanks that did it!
EddyR
A: 

This should do it (not tested):

select a.uid, a.field_value first_name, b.field_value last_name
from table2 a inner join table2 b on a.uid = b.uid 
where a.fid = 1 and b.fid = 2
Keeper