Hi,

You need to put the Join in the FROM section of the query, not the WHERE.

That is to say, move this

WHERE cust_id = 2 //// inner join Orders ON Customers.cust_id =
Orders.cust_id

to

FROM Customers inner join Orders ON Customers.cust_id = Orders.cust_id

You could acutally use this method instead, as the joining fields are the
same

FROM Customers inner join Orders USING (cust_id)

You might want to check out the mySQL manual on www.mysql.com - its damn
useful for getting the syntax of queries right! ;)

Also, you'll need to tell mySQL which custid field you want to filter by -
the WHERE clause needs a tweak. Currently its WHERE cust_id = 2 - however,
mySQL needs to know *which* cust_id to use, the Customers or Orders. Simply
add "Customers." before it and all is sorted.

So, the completed query would be:

SELECT Customers.Name, Customers.City, Orders.Product, Order.Price FROM
Customers inner join Orders USING (cust_id) WHERE customers.cust_id = 2

HTH.

Regards


Steve.
----- Original Message ----- 
From: "B. Fongo" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, August 15, 2003 8:44 AM
Subject: Query with inner join (Help!)


>
>
> Hello!
>
> I ' m trying to extra some information from 2 tables using inner join,
> but receive an error warning.  Am newbie so I' m not able to feature out
> why my queries don't work.
>
> Scenario:
>
> I have 2 tables: Customers and orders. The have following structures:
> Customers                             Orders
> cust_id Product
>  Name Price
>  City cust_id
>
>
> All that am trying to get out of these tables is to use a cust_id of a
> given customer to extract their orders. So I use something like this:
>
> SELECT Customers.Name, Customers.City, Orders.Product, Order.Price from
> Customers WHERE cust_id = 2 inner join Orders ON Customers.cust_id =
> Orders.cust_id
>
> Can anyone help me on this?
>
> Thanks
>
>



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to