|
WaterWolf
Starting Member
24 Posts |
Posted - 2009-10-14 : 09:47:24
|
| I have a view which selects from a table that applies an integer value to each row using row_number():SELECT ID, Name, Row_Number() OVER (ORDER BY (SELECT 1)) AS EmployeeNumberFROM tableAWhich returns something likeASD, Fred, 1ASB, Sam, 2ATD, Fred, 3FSD, Fred, 4Which is fine and as I want it.I am joining another view using the ID column. There can be multiple records with the same ID. The problem is that when joined, the row number changes rather than keeping its value from the first view. Eg: Sales, ASD, Fred, 1Marketing, ASD, Fred, 2Sales, ASB, Sam, 3IT, ATD, Fred, 4IT, FSD, Fred, 5when what I really wanted was:Sales, ASD, Fred, 1Marketing, ASD, Fred, 1Sales, ASB, Sam, 2IT, ATD, Fred, 3IT, FSD, Fred, 4Is there a way I can join these views while retaining the row_number() from the first view? As I'm using views here I can't use an auto number. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-14 : 09:50:35
|
| select required_columns from your_view as v inner join(SELECT ID, Name, Row_Number() OVER (ORDER BY (SELECT 1)) AS EmployeeNumberFROM tableA) as ton v.key_col=t.key_colMadhivananFailing to plan is Planning to fail |
 |
|