Can you check data in a table or another, but not both in a single query?

I have a situation where I need to connect the two tables, but the data can be in another table (archive) or different records are in both but I want the last disk in two tables:

ACCOUNT

AccountID name

John Doe 123

Jane 124 Donaldson

125 Harold Douglas

MARKETER_ACCOUNT

AccountID key Marketer StartDate EndDate

1001 123 10526 8/3/2008 9/27/2009

1017 123 10987 9/28 / 2009 12/31/4712 (high date ~ that means currently with this Distributor)

1023 124 10541 03/12/2010 12/31/4712

ARCHIVES

AccountID key Marketer StartDate EndDate

1015 124 10526 8/3/2008 12/02/2010

1033 125 10987 01/01/2011 01/31/2012

If my query should return the following:

123 John Doe 10526 8/3/2008 9/27/2009

Jane Donaldson 10541 12/03/2010 31/12/124 4712 (that is the later of the two folders for this account between tables Archives and marketer_account)

125 Harold Douglas 10987 01/01/2011 01/31/2012 (it is in the archives, so get this recording)

I'm not sure how to do this in a single query.  Beware, I am possibly reading several accounts at once and return to a .net collection

Open CURSOR_ACCT

Select the account ID

Of

ACCOUNT A,

MARKETER_ACCOUNT M.

R OF THE ARCHIVES

where A.AccountID = nvl ((select max (M.EndDate) of Marketer_account M2

where M2. AccountID is A.AccountID),

(select max (R.EndDate) in Archive R2

where R2. AccountID = A.AccountID)

and upper (B.SID) as a parameter. '%'

< can you do a NVL like that?   probably not...   I want to be able to get the MAX registration for this account on the table of MarketerACcount OR recording max for this account to off the table to Archive, but not the two >

(setting could be 'DO', so I return all names beginning with...)

Hello

So, you have a few lines in marketer_account and the other rows in the archives, but you do not want to treat all lines, as if it were a table, is it?

This sounds like a job for the UNION:

WITH union_data AS

(

SELECT StartDate, EndDate, Marketer, AccountID

OF marketer_account

UNION ALL

SELECT StartDate, EndDate, Marketer, AccountID

To archive

)

got_MaxEndDate AS

(

SELECT StartDate, EndDate, Marketer, AccountID

MAX (EndDate) ON (AccountID PARTITION) AS MaxEndDate

Of union_data

)

SELECT a.AccountID, B.SID

m.Marketer, m.StartDate, m.EndDate

One ACCOUNT

JOIN got_MaxEndDate m ON m.AccoutnID = a.AccoundID

WHERE m.EndDate = m.MaxEndDate

;

I hope that answers your question.
If this is not the case, after a CREATE TABLE and INSERT statements for your sample data.
Report when the above query is the production of incorrect results and explain, using specific examples, how to get results in these places.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).

See the FAQ forum: https://forums.oracle.com/message/9362002#9362002

.

Starting with version 8, the maximum year in DATEs Oracle is 9999, not 4712.

Tags: Database

Similar Questions

  • On my iPad, can I move files from one folder to another, but not in the Preview file, why?

    When you manage files in iCloud, from an iPad, I can move to the files from one folder to another, but not in the Preview file. Secondly, when I check the file Preview to iCloud from Mac content is so different when you look at an iPad. Why is the gap between the iPad and the Mac?

    Try to go to iCloud.com to see if the elements are there and whether the device or the computer. That should indicate if the device or computer is not synchronizing. If the computer, try going to System Preferences/iCloud and stop synchronization. Wait a few minutes, then recheck the timing. If the device, go to settings/iCloud and do the foregoing.

  • How can you check if you have a problem with the ghost attack

    How can you check if you have a problem with the ghost attack.

    My ISP (Virgin) sent me a letter saying I could have an attack on my apps by the phantom virus.

    How is this true and what can do

    The XcodeGhost malware affects the apps, mainly Chinese, created using a red version of Xcode.  It is not a 'virus '.  (Look at the difference between computer viruses and malware).  Remove the Apple listed here and get updated with the latest versions of the App Store.

  • How can I check if Oracle Enterprise Manager is installed or not?

    Customer uses Oracle 11g DB.

    How can I check if Oracle Enterprise Manager is installed or not?

    If you use EM DB control then you run this command,

    $ORACLE_HOME/bin/emctl status dbconsole

    HTH

    Mani

  • Can I load windows 7 32 bit on my laptop running 64 Vist bit.__Most of my programs are 32 bits, and does not on my version of vista.__If I can you I'll be able to upgrade and do not make a clean upload so I don't have to reload my programs?

    I want to upgrade to windows 7 32-bit

    Wrong forum; post questions here instead: http://social.answers.microsoft.com/Forums/en-US/w7install/threads

    Yes, you can switch to Vista 64-bit 32-bit Win7, but not via an upgrade in Place: you will have to make a "new installation (Advanced)" Win7 32 bit.

    ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • I have windows mail and can receive messages but not send, but I can't send when I go on my statement but not my e-mail account window, won't accept my password... was I get hacked or or why?

    I have windows mail and can receive messages but not send, but I can't send when I go on my statement but not my e-mail account window, won't accept my password... was I get hacked or or why?

    It seems to work now, so if my emails get screwed up again, I'll take your advice... don't understand why he sends now and am not asking my password as it does... but I don't want to do something that I don't know if it's working now... What do you think?

  • I can't enter in gmail. Error "page is not redirecting properly" is displayed. I can access gmail on my phone and with IE, but not firefox.

    I tried to clear the cache and delete cookies from gmail, but none worked. I can access gmail from my phone and through IE but not firefox. I also use the gmail gadget to my igoogle page and it does not work either.

    Tried all that precedes, and nothing has worked. I don't think it would be though, it is a new installation of windows 7 with very little installed. I wasn't expecting to find any virus/malware. The only thing found was an adware but removing those does not solve the problem.

    Edit: Uninstall and reinstall firefox did not work either.
    Edit2: I initially deleted all cookies associated with google and it does not work. I went back and remove all cookies, and it works now. Sorry I don't know what cookie was the cause of the problem.

  • How can you check if all your photos in Aperture are included in a backup?

    So I just manually backed up my iMac by clicking in the upper right of my screen on the logo of Time Machine and selected "save now".

    That's what I usually do I don't like TM backup automatically.

    My concern is "stored all my pictures from my Aperture library?" and "How do I check?"


    Can you also explain briefly, so I can understand that, what are the vaults?

    I use Aperture 3.4.5

    Thanks in advance

    If your Aperture library on your system drive or another drive that is included in your Time Machine backup, your Aperture library will appear in the Time Machine backup.

    Time Machine works well with Aperture 3.4.5.

    Opening vaults are a part inherited from the era when Time Machine works well with any libraries. You can use them to create a second backup copy of your photos to a different drive.  A vault is essentially a copy of your Aperture library, and when you update a vault, all changes since the last backup will be applied to this copy.  This is an incremental backup and it's faster then copy your library entirely more and more.

  • BlackBerry Smartphones Newbie Qs: How can you check what is stored in the memory card?

    In addition, it go out and check on PC, is possible to do this through BB?

    I just put 2 GB card and it's already full of 1.8 GB.

    I can represent 0.5 GB with photos and songs but as to know and to control its content.

    Verizon 8330 with 4.3 software.

    Thank you!

    Resale right.

    This solved all this.

    Thank you very much!

  • Can you check my final configuration? Two things still unclear

    Hey guys,.

    Just at the moment where I thought that I had everything figured, something new (at least for me) appears and raises more questions than answers. I'm going on and find more and more and now finally I think I have my allmost ready to order installation. Could you check it out and help out me on the final insecurities? Thanks a bunch.

    Oh and please, if you have a suggestion to change something, in my view, is already OK (so no questions)... it make a suggestion with enough information to make a choice in the matter. Give me a link to a Benchmarksite or e really good test. If the difference is minimal (seconds) on about 10 min. of the final sequence, just please don't send me on a chase again. My girlfriend I want to bed with her at the same time now after a week or two

    and I want to order the shit... stuff and start.http://forums.adobe.com/images/emoticons/wink.gif

    Camera: Canon XF 100, used Canon MPEG - 2 4:2:2 50Mbps codec

    Software: Adobe Premiere Pro CS5.53

    Motherboard: ASUS P8Z68-V Pro

    Question: not many landmarks on the Z68 autour combined with I have 2700. Anyone who uses this card with the 2700 or 2700K advance it please and develop.

    CPU: intel core I7 2600

    Memory: 16 GB Kingston ValueRAM (x 2 8 GB: 2 x 4 GB - DIMM 240-pin - DDR3 - 1333 MHz )

    or

    CPU: intel core I7 2600 K

    Memory: 16 GB Corsair Vengeance Blue 16 GB DDR3-1600 CL9 quad kit

    Question : I think I'd go for the first option. It's cheaper and what I read there is not much to gain. My videos for the most part do not exceed 10 minutes of final film. Anyone can recognize (or not)?

    Video card: MSI N570GTX-M2D12D5/OC

    Hard drive: OCZ Vertex 3 120 GB (sata 600) for my OS

    Hard drive: is sung WD Caviar Green WD20EARS x 3 (sata 300)

    Raid or non-raid is still not clear to me. 5 is definitely not a go

    I think I would put 2 drives in Raid 0 for more speed and on a regular basic backup to another (and possibly go external help)

    Is it "okay or mmh", then fine. Is it a "oh no, what he thinks", please tell me.

    Cooler: fake Mugen 2 B Rev.

    Accommodation: Cooler Master Xilencio

    Power supply: 620 Seasonic

    Monitor: Eizo EV2333WH-BK

    Economy car: LG BH10LS30

    Card reader: lexar LEXAR PROFESSIONAL USB 3.0 DUAL-SLOT READER (for CF canoncamera)

    Speakers Creative GigaWorks T20 Series II

    Special: Contour Design ShuttlePro2

    Thanks guys and girls (?) for I hope to make my life easier. Greeting from Nieuwegein, Utrecht, Netherlands

    Disc SSD is found to not more than give a faster boot time oh boy...

    At least for most animation.

    While they are useless, I saw all oohs and who impress the Gallery of anyone on this forum.

    Eric had no time to test, but we've been too busy had a guy with a detached retina make things worse.

    Now, we have sold one so she will be finally in about 2 weeks or so, perhaps sooner if he jumps on this system first.

    We had the tips here for weeks

  • Can you check if my earpods are authentic (with photos)

    Hi, I just bought a pair of new earpods to replace my "old" from a seller on eBay (with a store on the islands of Jersey www.onago.com). On the Bill, he said: it is a real product from Apple, and I paid for a product is genuine.

    When I opened the package, I was surprised by the difference in the quality of the cable. The cable is thinner and with a different material finished (more plastic and less rubberized texture). After that, I began to compare the two earpods and I found a lot of differences.

    My doubt is: Apple produced a new "version" of the earpods differences or I purchased a product of high quality replica?

    Different thickness of cable

    The grid/mesh model is different!

    On the case, serious Apple logo was different depths (on the new earpods depth is 0.1 mm vs 0.2 mm on the old/real ones)

    Can you confirm this information? I just opened an eBay business to ask for clarification.

    Hard to tell just from pictures. I suspect that it is a clone.

    Take a bar make genius with Apple for an assessment.

  • How can you save data of the iCloud on an external hard drive?

    How can I record data of the iCloud on an external hard drive?

    Is not possible. iCloud requires a Wi - Fi connection to synchronize data. Cannot do it on an external drive.

  • How can you check to see if your computer has a virus

    I have a MacBook Air OS X Yosemite 10.10.5 and I received an alert that said I had a virus and I need to download MacKeeper to get rid of it.  Is this a false alarm?  How can I check to see if I have a virus for real?

    MLP

    It's a scam, ignore. There is no virus affecting the Mac.

  • Not how to show a part of online data in a table in another table with even no column?

    I need to display the data from certain rows in a table in another table with the same numbers of columns and main table must be disabled. Could someone advice how to do this?    Data in the table are from the microprocessor and is intended the user can see and edit only some data.

    If someone can show me some advice, it will be a great help.

    Kind regards

    Annemariehoeven

    Disable a table: SetInputMode (panelHandle, controlID, 0);  ('1' to re - activate).

    Hide a table: SetCtrlAttribute (panelHandle, controlID, ATTR_VISIBLE, 0); ('1' to show it again).

    These commands are valid for each type of control.

    To extract values from the table, you can just use GetTableCellVal or GetTableCellRangeVals: If the range of cells has the same data type, you can use the second command which is faster; If the cells are different (for example digital and channels) you must solve each of them individually. The use of the Clipboard doesn't have this limitation.

  • Inserting data from one table to another table

    Hello

    I have the following SQL where I am updating a table by adding new data from another table, but without success.

    INSERT INTO
    () TOP_PROSPECTS
    COMMON_ID
    DATE_ADDED
    REVIEW_RANK
    EVAL_DATE
    PM_ASSIGN
    WHY_NOTES)
    SELECT
    t.COMMON_ID
    t.DATE_ADDED
    t.REVIEW_RANK
    t.EVAL_DATE
    t.PM_ASSIGN
    t.WHY_NOTES
    Of
    TEMP_IVAN_MARY t
    WHERE
    COMMON_ID <>t.COMMON_ID

    Any suggestions?

    Thank you.

    Published by: user13822709 on August 14, 2012 09:14

    Published by: user13822709 on August 14, 2012 09:15

    Is that what you're trying to do with the insert. I think there may be a sign {noformat}<{noformat}{noformat}>{noformat} missing in the where clause. This site eat those, so you need to use the equivalent! = post here.

    If I'm wrong about the missing trader, then it looks like you want to insert rows in temp_ivan_mary that are not already in top_prospects. If Yes, then you need something like:

    insert into top_prospects
       (common_id, date_added, review_rank, eval_date, pm_assign,
        why_notes)
    select t.common_id, t.date_added, t.review_rank, t.eval_date,
           t.pm_assign, t.why_notes
    from temp_ivan_mary t
    where t.common_id not in (select common_id from top_prospects
                              where common_id is not null)
    

    Function index and data available volumnes etc. then a mergr can be more effective. Something like:

    merge into top_prospects p
       using (select common_id, date_added, review_rank, eval_date,
                     pm_assign, why_notes
              from temp_ivan_mary) t
       on (p.common_id = t.common_id)
       when not matched then
          insert (common_id, date_added, review_rank, eval_date, pm_assign,
                  why_notes)
          values (t.common_id, t.date_added, t.review_rank, t.eval_date,
                  t.pm_assign, t.why_notes)
    from temp_ivan_mary t
    

    John

Maybe you are looking for

  • Upgrade Windows 8.1 on my W520

    Since the upgrade to windows 8.1, I have I had a problem where I couldn't run modern applications of Windows 8. Whenever I click on any of the applications, she looks like in his starts with the usual "flip 360 animation", and then immediately close.

  • Pavilion p7-1414: graphics card

    I recently bought a Nvidia Geforce GTX 560 ti and already plugged into my motherboard. My problem is that it is not find compatible hardware for the card (not sure I'm the right wording)

  • I disabled my own cookies and now I can't help? Windows XP and I use Mozilla Firefox?

    (Inadvertently), I disabled the cookies on my computer. Now I can't get to my Hotmail e-mail account. I went by the "tools/options/life exercise private and whatever he says 'enabled' (everything is checked).» I even restarted my computer, but nothin

  • Resolution changes and file/folder

    question 1 - when I turn on my computer, everything on my screen is enlarged by probably by 300%. I can barely see the top of the bottom task bar to stop it. When I turn the computer back on again, everything is normal. Enlargement will only occur wh

  • the button of the mouse to ebb in IE 4

    I tried searching the forums for this and got results much more 2 000. I crossed a little and decided to ask because I found nothing. I want to disable the mouse button as a shortcut for the back button in Internet Explorer 4. It's the most boring _