Jump to content

Performing a Join on Three tables


Recommended Posts

I want to perform a join on three tables.Table 1: part_masterColumn: Item, Item_statusTable 2: Order_DetailsColumn: Item, order_num, order_typeTable 3: OrderColumn: order_num, order_typeHere is the cardinality:part_master <--> order_details (1..1)order <--> order_details (1..n)I want to perform a search on order table, to retrieve item_status from part_master. In other word, I want to see item_status, for an order, using order_num as a search criteria.I tries something like this, however, it throws a exception:select part_master.item_status from part_master where item = (select item from order_details where order_details.order_num = order.order_num)The error says, the second 'select' statement returns multiple results which is not correct..Help....!

Edited by khadar
Link to post
Share on other sites

Use IN instead of an equal sign. You don't want to check if a value in a column is equal to an entire result set, you want to see if the value of the column is in that result set.

The error says, the second 'select' statement returns multiple results which is not correct..
I'm sure it's correct, trust the database. I'm sure you have multiple records in order_details that match something in order.
Link to post
Share on other sites
  • 2 weeks later...

Use IN instead of an equal sign. You don't want to check if a value in a column is equal to an entire result set, you want to see if the value of the column is in that result set.I'm sure it's correct, trust the database. I'm sure you have multiple records in order_details that match something in order.

You are right, there are multiple records in that select statement. I used IN instead of WHERE, and its working.. Thanks.

Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...