sql - How to do natural join when the common column have different names? -


i need natural join on 2 tables named customers , addresses (relationship 1:1), common column in tables key- id (according column natural join operate) . however- column in table customer called "id_customer", , in table addresses it's called- "id".

because of that, natural join doesn't work correctly, because program doesn't identify it's same column (by significance).

i can not change columns names same (because of many reasons..) there way make work- program understand same columns?

so don't use natural join. explicit join instead:

from customer c join      address      on a.id = c.id_customer 

also, wouldn't surprised if actual join condition were:

     on a.id_customer = c.id 

(when using id primary key of tables, practice include table name in foregn reference.)

as general rule, natural joins bad choice in long term. might store such queries in stored procedures, triggers, or applications. modifies table structure -- adds, removes, or renames column. and, code stops working.

i prefer use explicit joins.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -