Any idea for a SQL Query?

I have a table with 2 columns. I want to select the following rows:
a) any of the 2 rows where Row 1: col1, col2 = Row2: col2, col1
b) all other rows where there is no equality constraint
Example:
Col1 Col2
ABC001 || BC987
BC987 || ABC001
CDE || PH
BC987 || XYZ
Result should be
a) any of the first 2 rows because col1 value in 1st row is same as col2 value in 2nd row; and col2 value in 1st row is same as col1 value in 2nd row.
b) 2nd and 3rd rows (because these are unique rows)
Data setup:
create table temptab (col1 varchar2(20), col2 varchar2(20))
insert into temptab values ('ABC001', 'BC987')
insert into temptab values ('BC987', 'ABC001')
insert into temptab values ('CDE', 'PH')
insert into temptab values ('BC987', 'XYZ')
Thanks

Hi,
The ORDER BY clause of the ROW_NUMBER fucntion determines which row will be called #1, whcih will be #2, and so on.
I used
...                         ORDER BY        col1more or less arbitrarily. You can use anything you like, such as:
...                         ORDER BY        CASE
                                   WHEN  typ = 'Adaptive'
                                   THEN  1
                                         ENDThis means that, if any rows with typ='Adaptive' are in the group, then one of them will be labeled #1. Which one? Who knows (and who cares)? If you actually do care, then you can add another expression to the ORDER BY clause; just make sure you add it after the CASE expression, so that the new rule comes into play only after the 'Adaptive'/Other test has been done.
If 'Adaptive' is the first thing (in VARCHAR2 sort order) that can be in the typ column (and NULL comes after everything else), then you could simply say:
...                         ORDER BY        typPersonally, I don't hink that's a good idea. Suppose that, two years form mow, they make 'Aardvarkian' a valid typ. What are the chances that the person doing your job (even if that's you) is going to remember to change queries like this?

Similar Messages

  • TS1362 Everything works except the **** thing won't play. I push the play arrow or instruct it to play and it stays eternally paused. No problem buying things from these dogs,just can't play the when everthing pops up on screen.Any ideas for a hopeless ol

    Everything works on ITunes except play function.I can select as song I want but cannot get it off "pause."I tried going to controls and instructing it to play(no go) and clicking again and again on play arrow(which flips it to pause...).Any ideas for a very old,very frustrated non-tech guy???
    Please!! Thnaks!!!

    Replying to myself. Kept trying different areas of the ipod this evening, clicking various buttons, including some I'd never used before. All of a sudden I could see my Nano in iTunes. I quickly clicked on Restore before iTunes changed its mind about recognizing the iPod. Moved some songs onto it and it appears to be back to normal.  Keeping my fingers crossed. 

  • HT1384 My ipod nano 3rd generation, when connected by usb, does not show up in itunes, does not show up on my computer, does not seem to charge by the wall charger. It just has a black screen. Any ideas for me?

    My ipod nano 3rd generation, when connected by usb, does not show up in itunes, does not show up on my computer, does not seem to charge by the wall charger. It just has a black screen. Any ideas for me?
    I've run diagnostics. Can't find device. I've tried resetting. The toggle has been turned on and off.

    Cable works fine on my other iPod. Reset by pressing menu and center button together for 6-10 seconds. Left it to charge for many hours. Started acting up while running. Suddenly the music stopped playing but my Nike + was still working for the rest of my run. Took it straight it home and plugged it in to the wall to recharge since the battery was fairly low. Looked like it recharged ok but then screen went blank and now does it not show up on iTunes, does not seem to recharge by the wall charger (apple wall charger plugged into a surge protector in India). I have turned the hold switch off and on many times.
    Sounds like a repair issue, which is not easy to do in India :(

  • I bought an eBook from iTunes. I can view/read it perfectly on my iPhone but when I try to open the eBook file on my iPad, I get the error message, "Cannot open book. This book is protected by an incompatible technology." Any ideas for me? thx

    i bought an eBook from iTunes. I can view/read it perfectly on my iPhone but when I try to open the eBook file on my iPad, I get the error message, "Cannot open book. This book is protected by an incompatible technology." Any ideas for me? thx

    Welcome to the Apple Community.
    I have seen previous versions mentioned in a pop up message before on iCloud.com, but I'm not really sure at all how it would help, as I couldn't get it to do anything.
    The best advice I have at this time is to back up your work on your iOS device by regularly saving it to iTunes, if anything goes wrong you can then either load it into the numbers app again on the device or recover it via iTunes on your computer.
    My syncs are immediate, I never get chance to see if it works in the background, sorry.

  • My source audio isn't importing. Any ideas for how to fix?

    The audio is there. I've watched it in VLC, and the audio is there. Whenever I import the footage, though, it goes missing. Any ideas for how to fix it?

    Welcome to the forum.
    First, more information would be useful. See this FAQ Entry for what info will help: http://forums.adobe.com/thread/961741?tstart=0
    Also, when you Import your AV file, do you allow PrPro time to Conform the Audio portion? For more info on Conforming, Indexing and PEK file creation, see this article: http://forums.adobe.com/message/3892177#3892177
    Good luck,
    Hunt

  • Any ideas for a Birthday wishes video????

    Howdy folks,
    Thanks for taking a peak at this post. No technical problems--as of yet, but just wanted to hear from the crowd on some creativity with the apps.
    Any ideas for a background/slate to place behind people giving their best wishes to the birthday-boy?
    Editing on FCP, access to all of the CS applications--any thoughts on the matter would be appreciated.
    Thanks again for your time and have a great day,
    Liza

    Wow Bob,
    I can see that cowboy lasso/rope spinning on the top your head, but... watch out, I think you arm just hit your hat off your head... friendly.

  • Any ideas for a (fairly) simple program?

    Does anybody have any ideas for a fairly simple program that I could try to write (I am a fair programmer, but I'm not to creative)?

    You know, Java Game Programming for Dummies is actually a pretty good book (despite the "Dummies" part!) It is written in 1.0, but it has a "ponglet", card games, and several maze games. All the applets I've tried from them actually work (some typos in the book itself, but the CD is ok). Any of these could be "starter" code.
    Yahoo has a whole bunch of Java applet games. You could try to reproduce pieces of the games you see. (These are also interesting in the sense that you can immediately see what works in a game and what doesn't.)
    It is always fun to write little components. Cool buttons (write a nice little non-rectangular button that lights up or something), text boxes that look like digital displays, funny text labels (maybe with a weird font or with letters that jump all over the place when you mouse over them).. These don't take a whole lot of time to write, but write them well and they are very useful for your future games.
    Enjoy!
    :) jen

  • When I watch tv shows in Front Row that I've bought off iTunes the audio gradually falls out of sync with the video. It does not happen with other files that I have converted into mp4s. Any ideas for fixing this? It's a huge bummer...

    When I watch tv shows in Front Row that I've bought off iTunes the audio gradually falls out of sync with the video. It does not happen with other files that I have converted into mp4s. Any ideas for fixing this? It's a huge bummer...

    I too have the same problem.  The audio drop out of sync in about 5 sec in not uncommon for the audio to be 30+ sec behind video.  Apple needs to fix this!!!!!!!!!!!!!!!!   its a joke,  my iphone is all messed up after the last update as well.  at one time not to long ago apple products and software were top rated, not so much any more, more and more problems are showing up and apple is unwilling or unalbe to fix the many issues.  Apple needs to fix the audio sync problem, it not the computer hardware or other software it ITUNES!!!!,  there is no workaround other then hitting pause and hitting pause and hitting pause to temp fix the problem. 

  • I updated the software on my 2009 MBP to Mountain Lion. Since then, my iPhoto has been unable to open my photo library. I have updated iPhoto, and still no luck. Any ideas for fixing this problem?

    I updated the software on my 2009 MBP to Mountain Lion. Since then, my iPhoto has been unable to open my photo library. I have updated iPhoto, and still no luck. Any ideas for fixing this problem?

    Welcome to the Apple Support Communities
    Do you see any message when you open iPhoto? Try to open iPhoto holding Option key and select the library

  • HT201210 I am trying to download the latest version of itunes and it comes up error 3014 and error -1.  Any ideas for help?

    I am trying to restore my apple and update it.  It comes up error 3014 and -1.  Any ideas for help?

    Try the following user tip:
    Troubleshooting issues with iTunes for Windows updates

  • Looking for and SQL query to match CTI OS agent login ID with the Directory Number (instrument)

    Hi All,
    I am looking for an SQL query to request the HDS database to find out which Directory Number / instrument  was associated with a specific CTI OS agent login ID.
    Has anyone done such a query before ?
    Thanks and Regards
    Nick

    Hi,
    this should work in 8.0 and 8.5:
    SELECT
    ag.PeripheralNumber AS [LoginID],
    al.Extension,
    al.LogoutDateTime
    FROM [instance]_hds.dbo.Agent_Logout al
    JOIN [instance]_awdb.dbo.Agent ag ON al.SkillTargetID = ag.SkillTargetID
    Of course, replace [instance] with the ICM instance.
    The query returns a table with three columns, first is the login ID aka PeripheralNumber, Extension is... well, the agent's extension, and LogoutDateTime is the timestamp when the agent logged out.
    G.

  • The iBooks page on my iPad2 has locked. I cannot move on the page. I can close the page, and everything else is working fine. Does any one have any ideas for unlocking, resetting, or somehow getting the iBooks page to work? Thank you.

    The iBooks page on my iPad2 has locked. I cannot move on the page. I can close the page, and everything else is working fine. THis happened in the middle of a download. Does any one have any ideas for unlocking, resetting, or somehow getting the iBooks page to work? Thank you.

    Just re-set the App -
    Open the App
    Hold down the power button until the slider appears
    Hold down the home button (Don't use the slider) Until the App Closes
    You might lose your place, but shouldnt be too hard to find it again...

  • Wish I would have known Quicken 2007 would not work under Lion OS.  I had no reason to believe it wouldn't.  Any ideas for me?

    Wish I would have known Quicken 2007 would not work under Lion OS.  I had no reason to believe it wouldn't.  Any ideas for me?

    I switched to Essentials while using Snow Leopard in anticipation. Data conversion was pretty good. Nothing critical was lost, but I did have to reassign some budget catergories for past transactions. It was a good opportunity for some cleaning up that I should have done anyway. They have a 60-day return policy on the Quicken web site which was key to my purchase decision.
    I am not affiliated with Quicken in any way other than as a customer. I'd have preferred it if they had updated 2007 but they didn't!

  • Looking for an SQL query to retreive callvariables + ECC from a RUN SCRIPT RESULT (Translation to VRU)

    Hi Team,
    I am looking for an SQL query to check the data (ECC + CallVariable) received following a RUN SCRIPT RESULT when requesting an external VRU with a Translation Route to VRU with a "Run External Script".
    I believe the data are parsed between the Termination Call Detail + Termination Call Variable .
    If you already have such an SQL query I would very much appreciate to have it.
    Thank you and Regards
    Nick

    Omar,
    with all due respect, shortening a one day's interval might not be an option for a historical report ;-)
    I would recommend to take a look the following SQL query:
    DECLARE @dateFrom DATETIME, @dateTo DATETIME
    SET @dateFrom = '2014-01-24 00:00:00'
    SET @dateTo   = '2014-01-25 00:00:00'
    SELECT
    tcv.DateTime,
    tcd.RecoveryKey,
    tcd.RouterCallKeyDay,
    tcd.RouterCallKey,
    ecv.EnterpriseName AS [ECVEnterpriseName],
    tcv.ArrayIndex,
    tcv.ECCValue
    FROM Termination_Call_Variable tcv
    JOIN
    (SELECT RouterCallKeyDay,RouterCallKey,RecoveryKey FROM Termination_Call_Detail WHERE DateTime > @dateFrom AND DateTime < @dateTo) tcd
    ON tcv.TCDRecoveryKey = tcd.RecoveryKey
    LEFT OUTER JOIN Expanded_Call_Variable ecv ON tcv.ExpandedCallVariableID = ecv.ExpandedCallVariableID
    WHERE tcv.DateTime > @dateFrom AND tcv.DateTime < @dateTo
    With variables, you can parametrize your code (for instance, you could write SET @dateFrom = ? and let the calling application fill in the datetime value in for you).
    Plus joining two large tables with all rows like you did (TCD-TCV) is never a good option.
    Another aspect to consider: all ECC's are actually arrays (always), so it's not good to leave out the index value (tcv.ArrayIndex).
    G.

  • Any idea for high display resolution in application sharing server ?

    Hi.
    I installed EP6 SP 13 with KMC and configure collaboration feature.
    I tested application sharing and It works.
    Then, I found problem.
    Problem is that application sharing server doesn't support 1400x1050 display resolution. (only works till 1280x1024)
    Is there any idea for solving this issue ?
    Regards, Arnold.

    Hi Arnold,
    I'm afraid this screen resolution is not yet supported. The official supported screen resolution is 1024x768 ! but as you stated it <b>can</b> work wit 1280x1024. You could open an OSS ticket and ask the KM Development for plans on supporting higher resolutions in application sharing and let us also know.
    Hope this helps,
    Robert

Maybe you are looking for

  • HT5219 How would I connect dual monitors and also a firewire cable?  Macbook Pro (Retina)

    Currently I am using two thunderbolt to DVI connectors for the dual monitors, but I am left without any firewire cable connection for my audio interface. THe only adaptor I found was another thunderbolt to firewire, but since I already used these two

  • Mdm to xi settings

    hai friends iam creating mdm to xi scenario in that i have one probs. iam not under standing which type of bussiness system,technical system  i have to take i am think ing that third party object but how to configure the mdm in xi  that and any setti

  • Zen 6.5 and bc5755 nic

    Hi I was wondering if anyone has a tg3.0 file for the Broadcom 5755 nic. I am running Zen 6.5 with kernel 2.4.22. I downloaded the nic driver from Broadcom and tried to compile it on Dam Small Linux 3.4 but got a ton of errors when running the make c

  • HT4623 when is ios 7 available?

    I heard ios 7 was available today but it's not available as an update.  Anyone heard otherwise?

  • SCCM 2012 NAP Agent goes in and out of compliance approx every 2 min.

    I have deployed the SCCM 2012 NAP Agent on a few clients and it goes in and out of compliance approx every 2 min. So its compliant for 2 min then uncompliant for about 30 sec then compliant again. If I uninstall the single software update I have enfo