Posts

Showing posts from October, 2017

How to join multiple tables with multiple keys / columns in SQL

Image
Some short instructions on how to accomplish a join on three or more SQL database tables but also using multiple keys/columns as well. Good StackOverflow reference: https://stackoverflow.com/questions/24639504/mysql-join-3-tables-using-multiple-columns-keys Three different tables used: 1. UserDivisions An old legacy table containing Division and it's ID: 2. MediaCategoryDivisionMap This table maps the Division ID of the first table to the Category ID of a newer MediaCategories table: 3. MediaCategories Finally the newer table that uses a Category ID: I wish to use the Division IDs in table UserDivisions in order to extract the equivalent Category IDs they are mapped to in MediaCategoryDivisionMap and therefore obtain the new Name contained in the MediaCategories table. As the StackOverflow post states "INNER JOIN creates a new result table by combining column values of two tables (A and B) based upon the join-predicate. The query compares each row ...