Tony Tony - 4 years ago 137
SQL Question

Using INNER JOIN to link mutliple columns from two tables

I'm using XAMPP and I have two tables, customers and table2.

Customers has the following columns:

Customer_Name
,
Address
,
City
,
State

table2 has the following columns:
City
,
State
,
Zip_Code


The tables were created to achieve 3rd normalization. I don't have a problem using a single INSERT statement to load data to each table, but I'm unable to use INNER JOIN to combine the tables and run my query. Here's what I have so far:

SELECT Customer_Name, Address, City, State FROM customers
INNER JOIN table2 ON customers.City=table2.City
INNER JOIN table2 ON customers.State=table2.State;


The error being returned is


#1066 - Not unique table/alias: 'table2'


Any help would be appreciated.

Answer Source

Does

SELECT c.Customer_Name, c.Address, c.City, c.State FROM customers c
INNER JOIN table2 t2 ON c.City=t2.City and c.State = t2.State

works?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download