Merge two queries into one. [SOLVED]
Posted: Tue Apr 12, 2005 4:25 am
Hi guys,
I have another one of these problems, trying to get one query doing the job of two. Most of the time I have been able to get a solutio, but this one is complex because I think it needs to use two aliases of the same table to work.
The two aparts are as follows:
To list the items belonging to user 8, of type 12.
To see how many times a specifi item has been referenced in a recipe.
Basically, what I am hoping to wind up with is a list of the different options belonging to a specific user, in order of the most used items to the least / unused items.
I know it is probrably difficult to work all this out from these queries ... god knows I cant ... but if you can see any way to get both of these tasks done it would be most appreciated.
Using mySQL if it helps.
Cheers.
I have another one of these problems, trying to get one query doing the job of two. Most of the time I have been able to get a solutio, but this one is complex because I think it needs to use two aliases of the same table to work.
The two aparts are as follows:
To list the items belonging to user 8, of type 12.
Code: Select all
SELECT 'tbl_master_items'.'name', 'tbl_vendor_product'.'VI_PK' FROM 'tbl_vendor_product' INNER JOIN 'tbl_master_items' ON ('tbl_vendor_product'.'MI_ID'='tbl_master_items'.'MI_PK') WHERE ('tbl_master_items'.'MI_ID'='12') AND ('tbl_vendor_product'.'_ID'='8')Code: Select all
SELECT COUNT ('tbl_vendor_recipe_ingredients'.'VRI_PK') AS 'count' FROM 'tbl_vendor_recipe_ingredients' INNER JOIN 'tbl_vendor_product' ON ('tbl_vendor_recipe_ingredients'.'VR_ID' = 'tbl_vendor_product'.'VI_PK') WHERE ('tbl_vendor_recipe_ingredients'.'VI_ID'='271') AND ('tbl_vendor_product'.'V_ID'='8')I know it is probrably difficult to work all this out from these queries ... god knows I cant ... but if you can see any way to get both of these tasks done it would be most appreciated.
Using mySQL if it helps.
Cheers.