0

Okay, first following are my tables:

Table house:

id | items_id |

1 | 1,5,10,20 |


Table items:

id | room_name | refer

1 | kitchen | 3

5 | room1 | 10


Table kitchen:

id | detail_name | refer

3 | spoon | 4

5 | fork | 10


Table spoon:

id | name | color | price | quantity_available |

4 | spoon_a | white | 50 | 100 |

5 | spoon_b | black | 30 | 200 |

How to do a nested select statement, where I want to select id, name, color, price and quantity_available column, from the each value inside the 'items_id' column in 'house' table?

This is very challenging!!

EDIT:

after read robin's answer

Table house:

id | items_id |

house1 | 1 |

house1 | 5 |

house1 | 10 |

house2 | 20 |

If this it the house table, how to do the nested, join, or whatever select statement??

3
  • In the 'house' table, how is '1,5,10,20' stored? Just as a string with multiple numbers like that? Commented Oct 21, 2009 at 8:37
  • @Alex: yes Alex, currently is a string with comma as separator Commented Oct 21, 2009 at 8:43
  • Relationships between the tables are not very clear, at least to me. You should normalize the house table, but to help you with the select we need to know what ID references what. Commented Oct 21, 2009 at 8:47

1 Answer 1

1

The complexity appear to be in your "house" table.

You should not store ID's as a comma separated list, instead, you should have a separate row for each of the item id's.

Once you split that out you should find that you can produce any results you need with just simple joins.

Sign up to request clarification or add additional context in comments.

2 Comments

@robin: if i separated the house string into rows, how to use the joins query?(simple joins??
Take a look at the W3Schools SQL Joins tutorial: w3schools.com/Sql/sql_join.asp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.