Jump to content

Performing a Join on Three tables


khadar

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 comment
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 comment
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 comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...