![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Hi Everyone, I have a scenario where I will need a rownum value for a query. I have attempted to make this by doing a self join type query based on the 'original' querydef and counting the records. I am getting results that dont make any sense and I am not sure why. My 'base' query is made up from data that spans three tables (category, subcategory, segment). I am selecting all segments by subcategory by category. One big list (actually not that big, but important). The sql [qryProductFilters] is as follows: SELECT category.category, subcategory.subcategory, segment.segment FROM (category INNER JOIN subcategory ON category.category_id = subcategory.category_id) INNER JOIN segment ON subcategory.subcategory_id = segment.subcategory_id ORDER BY category.category, subcategory.subcategory, segment.segment; So far so good. I am buggered if I can get an artificial rownum to work on this query. I based another query on this one to try and produce the rownum: SELECT [qryProductFilters].*, (select count(*) from [qryProductFilters] as SELF where SELF.[category] <= [qryProductFilters].[category] AND SELF.[subcategory] <= [qryProductFilters].[subcategory] AND SELF.[segment] <= [qryProductFilters].[segment]) AS ROWNUM FROM qryProductFilters ORDER BY [qryProductFilters].[category], [qryProductFilters]. [subcategory], [qryProductFilters].[segment]; I am getting duplicate ROWNUM values and they are jumbled all over the place to boot. I am guessing that it is related to the multiple field 'unique key' . Does anyone have a workaround for this? Another approach perhaps? I need to avoid a temp table if I can FWIW. Any guidance greatly appreciated Cheers The Frog |
#4
| |||
| |||
|
|
Hi Everyone, I have a scenario where I will need a rownum value for a query. I have attempted to make this by doing a self join type query based on the 'original' querydef and counting the records. I am getting results that dont make any sense and I am not sure why. My 'base' query is made up from data that spans three tables (category, subcategory, segment). I am selecting all segments by subcategory by category. One big list (actually not that big, but important). The sql [qryProductFilters] is as follows: SELECT category.category, subcategory.subcategory, segment.segment FROM (category INNER JOIN subcategory ON category.category_id = subcategory.category_id) INNER JOIN segment ON subcategory.subcategory_id = segment.subcategory_id ORDER BY category.category, subcategory.subcategory, segment.segment; So far so good. I am buggered if I can get an artificial rownum to work on this query. I based another query on this one to try and produce the rownum: SELECT [qryProductFilters].*, (select count(*) from [qryProductFilters] as SELF where SELF.[category] <= [qryProductFilters].[category] AND SELF.[subcategory] <= [qryProductFilters].[subcategory] AND SELF.[segment] <= [qryProductFilters].[segment]) AS ROWNUM FROM qryProductFilters ORDER BY [qryProductFilters].[category], [qryProductFilters]. [subcategory], [qryProductFilters].[segment]; I am getting duplicate ROWNUM values and they are jumbled all over the place to boot. I am guessing that it is related to the multiple field 'unique key' . Does anyone have a workaround for this? Another approach perhaps? I need to avoid a temp table if I can FWIW. Any guidance greatly appreciated Cheers The Frog |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Hi Salad, thanks for having a crack at it. I ended up taking a completely different approach, one where a series of sub-selects are used to populate the columns as needed. |
![]() |
| Thread Tools | |
| Display Modes | |
| |