Solved

MyQL JOIN query

Posted on 2010-09-05
8
292 Views
Last Modified: 2013-12-13
I am trying to write a query that joins two tables together
The first table is called customers and the info I need from that table is customerid, name and email
The second table is called orders and it also contains the customerid. This table also contains a column called order_status and this holds the key to the query.
In laymen’s language the query should be:
I need customerid, name, email from table customers (join table customers on table orders using customerid as the joiner) where order_status  is equal to “FULL”

I have tried this myself and come up with:
SELECT  customerid, name, email
FROM customers  JOIN orders ON customers. customerid = customers.customerid
WHERE order_status = FULL
But this does not work
Assistance much appreciated.
N
0
Comment
Question by:Neil_Bradley
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Expert Comment

by:Manish
ID: 33608975
SELECT  customerid, name, email
FROM customers  JOIN orders ON customers. customerid = orders.customerid
WHERE order_status = 'FULL'  (if order_status is varchar type)
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 33609053
Hi,

SELECT  
           customerid, name, email
FROM
         customers  
JOIN
        orders ON
      customers. customerid = orders .customerid
WHERE
    order_status = 'FULL'

Hope it helps.

Is it that data in orders is not optional .
IF yes then use 'LEFT JOIN' instead of just 'JOIN'
0
 
LVL 5

Author Comment

by:Neil_Bradley
ID: 33609205
I am getting an error
"customerid in field list is ambigious"

Your answers should work but... I have ckecked again the names of the colums but cant spot the issue.
N
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 13

Accepted Solution

by:
p_nuts earned 250 total points
ID: 33609223
select customers.customerid, name , email from customers inner join orders on orders.customerid = customers.customerid where orders.order_status = 'FULL'

you need to name the table.field if there are more options
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 33609329
SELECT  
          orders.customerid, name, email
FROM
         customers  
JOIN
        orders ON
      customers. customerid = orders .customerid
WHERE
    order_status = 'FULL'

give columnname.name ,columnname.email
0
 
LVL 15

Assisted Solution

by:Insoftservice
Insoftservice earned 250 total points
ID: 33609335
SELECT  
          orders.customerid, customers.name, customers.email
FROM
         customers  
JOIN
        orders ON
      customers. customerid = orders .customerid
WHERE
    order_status = 'FULL'
0
 
LVL 5

Author Closing Comment

by:Neil_Bradley
ID: 33609429
Thanks for the solutions. p_nuts you got there first however insoftservice got the answer corect too. Thanks for your support. I can clock off work now!
N
0
 
LVL 11

Expert Comment

by:Manish
ID: 33609516
:(
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question