Forum Moderators: coopster
SELECT widget_name, widget_description, widget_category, widget.widget_id
FROM user_widgets
LEFT JOIN widget ON widget.widget_id
WHERE user_id =$user_id AND user_widgets.widget_id = widget.widget_id
I'm new to DB's and this is my first ever join query. What am I doing wrong?
TIA
LEFT JOIN widget ON user_widgets.widget_id=widget.widget_id
You can remove this comparison from your WHERE clause also.
When joining tables it is always a good idea to explictly name your columns like tablename.columnname.
I'd say its better to use aliases that you can set in most databases by specifying an alias after table name in the query ie: select Alias.* from table_a Alias
Aliases are better since you won't have to change lots of things in the query if you change table name.
Yeah you could do that -- I did not mention the main benefit of aliases -- readability. If you start using table names everywhere code will become less readable (especially if you deal with lots of columns in joining).