0

There are two tables named Customers and Payments. They both have the "CustomerNumber"

Here's what i am trying to do.

Select checkNumber, amount, CustomerNumber, CustomerName
FROM Payments, Customers

And i get an error saying : Unknown column....` in 'field list'

I also tried doing this query

Select checkNumber, amount, Payments.CustomerNumber, CustomerName
FROM Payments, Customers

It didn't work T_T

i tried this one

Select checkNumber, amount, customerNumber, customerName FROM payments, customers

I get this error "Column 'customerNumber' in field list is ambiguous"

7
  • Can you add the exact SQL query to your post? Commented Oct 12, 2012 at 16:24
  • Please add the real code and real table names. As is I'm tempted to close as too vague. Commented Oct 12, 2012 at 16:28
  • CustomerName != customerName. Commented Oct 12, 2012 at 16:53
  • There, i just edited it and put the real table names. Sorry about that Commented Oct 12, 2012 at 16:53
  • You can use Alias to get your answer!!! Commented Oct 12, 2012 at 16:55

2 Answers 2

1

This error happends when there're 2 columns with the same name in 2 tables, so you have to specify the same column in which table, i.e :

Select checkNumber, amount, Customers.CustomerNumber, CustomerName
FROM Payments, Customers

or try to make all of your table name and column quoted in ` like this:

Select `checkNumber`, `amount`, `Payments.CustomerNumber`, `CustomerName`
FROM `Payments`, `Customers`
Sign up to request clarification or add additional context in comments.

1 Comment

be aware that MySQL is case sensitive with table names when the MySQL server being used is hosted on a Linux machine. `SELECT checkNumber, amount, Customers.CustomerNumber, CustomerName FROM Payments, Customers WHERE Customers.CustomerNumber = Payments.CustomerNumber' should definitely work. The WHERE clause, or the JOIN clause as posted earlier is highly recommended when u want to read the correct payments for the customers :)
0

Are your tables named 1 and 2?

If they are, then mysql is probably not recognizing 1 and 2 as table names, but as numbers. Try enclosing the table names with backticks:

select `1`.CustomerName, lastName, street, state
from `1`, `2`

By the way, this will give you every possible combination of rows... be careful (or use a join)


UPDATE

Given the new data in your comment:

Check the field names... field names must be written exactly as the names in the table(s). Notice that you're writing payments.customerNumber in the select section and payments.customersNumber in the from section

2 Comments

SELECT checkNumber, amount, payments.customerNumber, customers.customerName FROM payments INNER JOIN Customers ON payments.customersNumber=customers.customersNumber ----------This is what im doing right now and im still getting an error and no they arent named 1 and 2. Those are just examples.
that didn't work. I just checked the spelling again. like you said it was wrong. But that didn't solve anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.