| Author |
Topic |
|
palbar
Starting Member
8 Posts |
Posted - 2012-04-12 : 12:08:42
|
| When I run the following query:SELECT FMR_TABLE_ID_NO, FMR.TABLE_FIRST_NAME||' '||FMR.TABLE_MI||' '||FMR.TABLE_LAST_NAME AS FORMER_NAME, ROW_NUMBER() OVER (PARTITION BY FMR.TABLE_ID_NO ORDER BY FMR.TABLE_ACTIVITY_DATE) AS RNFROM TABLE FMRWHERE FMR.TABLE_CHANGE_IND IS NOT NULLAND FMR.TABLE_NTYP_CODE = 'FRMR'I get:FMR_TABLE_ID_NO FORMER_NAME RN11111 Danny Test 122222 Amanda Gomez 133333 Cheryl Campbell 133333 Cheryl Mitchell 244444 Cindy Joy 155555 Carol Kean 155555 Carol Cashman 266666 Dennis Sanders 177777 Albert Eden 1What I'm trying to accomplish is to return only those rows that equal 1. I've been searching on a way to do it but I haven't any luck, could somebody please give me a hand, unfortunately the FMR.TABLE_ACTIVITY_DATE are the same for those with more than 1 row. This will be used in a view I'm writing. |
|
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2012-04-12 : 12:19:56
|
| try adding ROWNUM=1 in your where clause. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-12 : 17:43:44
|
| [code]SELECT columns...FROM(SELECT FMR_TABLE_ID_NO, FMR.TABLE_FIRST_NAME||' '||FMR.TABLE_MI||' '||FMR.TABLE_LAST_NAME AS FORMER_NAME,ROW_NUMBER() OVER (PARTITION BY FMR.TABLE_ID_NO ORDER BY FMR.TABLE_ACTIVITY_DATE) AS RNFROM TABLE FMRWHERE FMR.TABLE_CHANGE_IND IS NOT NULLAND FMR.TABLE_NTYP_CODE = 'FRMR')tWHERE RN=1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
palbar
Starting Member
8 Posts |
Posted - 2012-04-12 : 19:30:00
|
The "columns..." I want is the concatenation of the first_name, mi and last_name (just one column). When I put FMR.TABLE_FIRST_NAME||' '||:FMR.TABLE_MI||' '||FMR.TABLE_LAST_NAME where columns..." is, I get an error that says: ORA-00904:"FMR"."TABLE_LAST_NAME":invalid identifier 00904.00000 - "%s:invalid identifier"SELECT FMR.TABLE_FIRST_NAME||' '||FMR.TABLE_MI||' '||FMR.TABLE_LAST_NAME AS FORMER_NAMEFROM(SELECT FMR.TABLE_FIRST_NAME||' '||FMR.TABLE_MI||' '||FMR.TABLE_LAST_NAME AS FORMER_NAME,ROW_NUMBER() OVER (PARTITION BY FMR.TABLE_PIDM ORDER BY FMR.TABLE_ACTIVITY_DATE) AS RNFROM TABLE FMRWHERE FMR.TABLE_CHANGE_IND IS NOT NULLAND FMR.TABLE_NTYP_CODE = 'FRMR') TWHERE RN = 1 |
 |
|
|
vinu.vijayan
Posting Yak Master
227 Posts |
Posted - 2012-04-13 : 01:25:49
|
Try This:SELECT FMR_TABLE_ID_NO, FMR.TABLE_FIRST_NAME||' '||FMR.TABLE_MI||' '||FMR.TABLE_LAST_NAME AS FORMER_NAME,ROW_NUMBER() OVER (PARTITION BY FMR.TABLE_ID_NO ORDER BY FMR.TABLE_ACTIVITY_DATE) AS RNFROM TABLE FMRWHERE FMR.TABLE_CHANGE_IND IS NOT NULLAND FMR.TABLE_NTYP_CODE = 'FRMR' AND RN = 1 Vinu VijayanN 28° 33' 11.93148"E 77° 14' 33.66384" |
 |
|
|
palbar
Starting Member
8 Posts |
Posted - 2012-04-13 : 09:29:27
|
| [code]SELECT FORMER_NAMEFROM(SELECT FMR.TABLE_FIRST_NAME||' '||FMR.TABLE_MI||' '||FMR.TABLE_LAST_NAME AS FORMER_NAME,ROW_NUMBER() OVER (PARTITION BY FMR.TABLE_PIDM ORDER BY FMR.TABLE_ACTIVITY_DATE) AS RNFROM TABLE FMRWHERE FMR.TABLE_CHANGE_IND IS NOT NULLAND FMR.TABLE_NTYP_CODE = 'FRMR') TWHERE ROWNUM = 1[/code]I've written the above code and it only returns the first row:Danny Testwhere it should return:Danny TestAmanda GomezCheryl CampbellCindy JoyCarol KeanDennis SandersAlbert EdenI just need the former name and if the person has more than 1 former name I just want the 1st row.eg. from the above exampleCheryl Campbell and Cheryl Mitchell are the same person but I want Cheryl Campbell because her "RN" is 1;Carol Kean and Carol Cashman are the same person but I wantCarol Kean because her "RN" is 1. |
 |
|
|
palbar
Starting Member
8 Posts |
Posted - 2012-04-13 : 09:34:37
|
quote: Originally posted by vinu.vijayan Try This:SELECT FMR_TABLE_ID_NO, FMR.TABLE_FIRST_NAME||' '||FMR.TABLE_MI||' '||FMR.TABLE_LAST_NAME AS FORMER_NAME,ROW_NUMBER() OVER (PARTITION BY FMR.TABLE_ID_NO ORDER BY FMR.TABLE_ACTIVITY_DATE) AS RNFROM TABLE FMRWHERE FMR.TABLE_CHANGE_IND IS NOT NULLAND FMR.TABLE_NTYP_CODE = 'FRMR' AND RN = 1 Vinu VijayanN 28° 33' 11.93148"E 77° 14' 33.66384"
quote: Gave me an error:0RA-00904: "RN": invalid identifier00904.00000 - "%s:invalid identifier"
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-13 : 11:10:32
|
| you should have told this before.Ther error message clearly suggest you're using Oracle0RA-00904: "RN": invalid identifierThis is MS SQL SERver forum and solutions given here are mostly sql server specific. So please post in some oracle forum like www.orafaq.com if you need Oracle specific help------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
palbar
Starting Member
8 Posts |
Posted - 2012-04-13 : 11:19:31
|
quote: Originally posted by visakh16 you should have told this before.Ther error message clearly suggest you're using Oracle0RA-00904: "RN": invalid identifierThis is MS SQL SERver forum and solutions given here are mostly sql server specific. So please post in some oracle forum like www.orafaq.com if you need Oracle specific help------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
So sorry!!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-13 : 11:33:25
|
quote: Originally posted by vinu.vijayan Try This:SELECT FMR_TABLE_ID_NO, FMR.TABLE_FIRST_NAME||' '||FMR.TABLE_MI||' '||FMR.TABLE_LAST_NAME AS FORMER_NAME,ROW_NUMBER() OVER (PARTITION BY FMR.TABLE_ID_NO ORDER BY FMR.TABLE_ACTIVITY_DATE) AS RNFROM TABLE FMRWHERE FMR.TABLE_CHANGE_IND IS NOT NULLAND FMR.TABLE_NTYP_CODE = 'FRMR' AND RN = 1 Vinu VijayanN 28° 33' 11.93148"E 77° 14' 33.66384"
Did you test this?I dont think it will workPlease test your code before posting------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|