Reputation: 79
I have this column named "id". whenever I try to inner join like this "inner join tblBarangay as LB USING(id) I get an error Unknown column 'id' but when I try to rename it to 'brgy_id' it works (Is the word id in MYSQL is a function name?). I don't want to rename it because many of my PHP code queries will then needed to be changed. Now, how can I make it work without renaming the column name? Thanks.
TableA:
-------------------------------------------
id | brgy_name | description
1 New York a city
TableB:
Upvotes: 0
Views: 783
Reputation: 11
What is the schema of second table, may be you dont have Id in second table "TableB"
Upvotes: 0
Reputation: 24960
I don't use using
because first off I am too dense. Second, it is too implicit and I like to be explicit so I understand it and others too. So, if you just don't use using
(because they don't have id
in common as column names) you are all set by explicitly joining with table1.id = table2.whatever
. And you don't have to alter your table at all.
The Takeaway: Don't use using
for this situation. And don't confuse USING
with some mandate that you need to alter your table forever, thus messing up all you other queries that work just peachie.
From the MySQL Manual Page entitled JOIN Syntax:
Upvotes: 1