Tony
Tony

Reputation: 298

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.

Upvotes: 0

Views: 1556

Answers (1)

Phiter
Phiter

Reputation: 14992

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?

Upvotes: 4

Related Questions