in SQL, why is this JOIN returning the key column twice?

Answer #1 85.7 %

SELECT * returns all columns from all tables of the query. That includes both user_id columns - one from table A, one from table B.

The best practice is to list the column names you want returned specifically, though another option to shorten the list would be:

SELECT TableA.*, 
       TableB.col1, 
       TableB.col2, 
       ...rest of B columns except user_id

You’ll also like:


© 2023 CodeForDev.com -