Monday, March 26, 2012

problem regarding foreign key

i have 3 table which is merchant, merchantcategory and merchantitem.

merchantcategory's foreign key is refer to merchant_id, and merchantitem's foreign key is refer to merchantcategory_id.....

the problem is like this...

i would like to select all the available items from merchantitem, but i only have the information of merchant_id, so what method should i use to get these output ??

i am using the functions which generated by codesmith with wilson ORMapper method....

i really hope that someone will provide me the solution.....thanks

If I understand correctly, I think:

SELECT merchant.Name, merchantitem.someitem1, merchantitem.someitem2, merchantitem.someitem3
FROM (merchant INNER JOIN merchantcategory ON merchant.Merchant_ID = merchantcategory.merchant_id) INNER JOIN merchantitem ON merchantcategory.merchantcategory_id = merchantitem.merchantcategory_id;

should be pretty much what you need.

hth

|||

thanks fUNKYgIBBON

i know this method......but now i am using the functions which is generated by codesmith...

so i cannot use this method......

No comments:

Post a Comment