Solved

MyQL JOIN query

Posted on 2010-09-05
8
285 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 13

Accepted Solution

by:
p_nuts earned 250 total points
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 15

Expert Comment

by:Insoftservice
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
:(
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now