If I want to write a query with a simple join, I can do this:
select * from customer c
join order o
on c.customerid = o.customerid
where c.customerid = 100
and it all works fine. In this query, is there a reason why I have to specify a table alias – ie. c.customerid? Why can’t I just write this:
select * from customer c
join order o
on c.customerid = o.customerid
where customerid = 100
I get the error Ambiguous column name 'customerid'. In this case, where there’s only one column in the WHERE clause and it’s the column on which I’m JOINing, is this actually “ambiguous”? Or is it just to comply with the ansi-standard (I’m guessing here – I don’t know if it does comply) and to encourage good coding conventions?
For your specific example I can’t think of any circumstances in which it would make a difference. However for an
INNER JOINon a string column it could do as below.