Solved

MyQL JOIN query

Posted on 2010-09-05
8
293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Node.js 11 76
Export Data from MySql Using PHP 16 65
Format Date 7 27
Change background images after 5 seconds. 12 46
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

737 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