Jump to content

Recommended Posts

Hi, 
I have multiple table 
Table -1 
order_no name 
1 raj 

table -2 
order_no name 
1 raj 

table 3 
order_no name 
1 raj 

table 4 
order_no name 
1 raj 

table 5 
order_no name 
1 raj 

I want a query to check if the id (one) is present in all tables or not, 
i create this. 


select order_no from prepress, press, postpress, qc, binding, dispatch where order_no=prepress.order_no AND order_no=press.order_no AND order_no=postpress.order_no AND order_no=qc.order_no AND order_no=binding.order_no AND order_no=dispatch.order_no 
but the ambiguous error for order_no. 

how to achieve this can anyone suggest me? 
thanks

But you are storing the same information to different table, just with different values. Table1, Table2 etc all have the same format.

 

Or am I being misled by a poor naming in the question and they are supposed to be the press, prepress, postpress, qc, binding and dispatch (six) tables in your query? Why not say so if that is the case?

 

Assuming that is the case the ambiguity is caused by your use of order_no in the WHERE clause without a qualifying table name. Don't use that syntax for table joins, use more efficient explicit joins

SELECT order_no 
FROM prepress
    INNER JOIN press ON press.order_no=prepress.order_no
    INNER JOIN postpress ON postpress.order_no=prepress.order_no
    INNER JOIN qc ON qc.order_no=prepress.order_no
    INNER JOIN binding ON binding.order_no=prepress.order_no
    INNER JOIN dispatch ON dispatch.order_no=prepress.order_no 

 

But you are storing the same information to different table, just with different values. Table1, Table2 etc all have the same format.

 

Or am I being misled by a poor naming in the question and they are supposed to be the press, prepress, postpress, qc, binding and dispatch (six) tables in your query? Why not say so if that is the case?

 

Assuming that is the case the ambiguity is caused by your use of order_no in the WHERE clause without a qualifying table name. Don't use that syntax for table joins, use more efficient explicit joins

SELECT order_no 
FROM prepress
    INNER JOIN press ON press.order_no=prepress.order_no
    INNER JOIN postpress ON postpress.order_no=prepress.order_no
    INNER JOIN qc ON qc.order_no=prepress.order_no
    INNER JOIN binding ON binding.order_no=prepress.order_no
    INNER JOIN dispatch ON dispatch.order_no=prepress.order_no 

thanks that's because there are several other value will be in all six tables. but these two values will be same to check.

and i get the solution as you provide

SELECT prepress.order_no 
  FROM prepress
INNER
  JOIN press
    ON press.order_no = prepress.order_no 
INNER
  JOIN postpress
    ON postpress.order_no = prepress.order_no 
INNER
  JOIN qc
    ON qc.order_no = prepress.order_no 
INNER
  JOIN binding
    ON binding.order_no = prepress.order_no 
INNER
  JOIN dispatch 
    ON dispatch.order_no = prepress.order_no
 WHERE prepress.order_no ='$order_num'";

thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.