Seryu
Seryu

Reputation: 163

Adding specific column by getting column in other table

My problem is merging this two tables into 1, having the parent table is tbl1.

tbl1
userid | Checkin | checkout

tbl2
userid | Name | Department 

I run this, and come up with an error

"ambiguous field list"

SELECT userid, checkin, checkout
from tbl1
join tbl2
on tbl1.userid = tbl2.userid
order by tbl1.userid

I want my table to like this:

userid | Checkin | checkout | Name | Deparment

Upvotes: 1

Views: 45

Answers (2)

Abdul Rasheed
Abdul Rasheed

Reputation: 6729

Both tables have column userid, so you have to specify the table or table alias along with the selected columns.(tbl1.userid or tbl2.userid )

SELECT tbl1.userid, checkin, checkout, Name, Department 
from tbl1
join tbl2
on tbl1.userid = tbl2.userid
order by tbl1.userid

Upvotes: 1

Blank
Blank

Reputation: 12378

Try this;)

SELECT tbl1.userid, checkin, checkout, Name, Department
from tbl1
join tbl2
on tbl1.userid = tbl2.userid
order by tbl1.userid

Upvotes: 1

Related Questions