last album back in a subquery

Hi, I have the following table:


Table_a

record_id def_id Date
111June 7
134June 1
155May 5
234June 4
211May 8

Table_A_DEF

def_id def_name
11Examine
34definitionF
50DEFINITIONH
55definitionN

Table_B

record_id record_name
1Record1
2Record2
3record Record3

I need to check if there are records from Table_A 'examine' or 'definitionN' as their last entry.

So, in that the above example, I would expect only record 1 to return as his last entry in the table def_id = 11.

That's what I have, but obviously does not work as it throws an error on the max function, can someone please help with it?

select * from Table_B b
where exists (
  select * from Table_A a
            where a.record_id in (b.record_id) and max(a.def_id) in (
            select ad.def_id from Table_A_DEF ad where ad.def_name in ('definitionA', 'definitionN')
  )

Here's a way (using either exist or subquery in the list)...

with Table_A (record_id, def_id, date_A) as)

Select 1, 11, date ' 2015-06-07 the Union double all the

Select day 1, 34, '' 2015-06-01 Union double all the

Select 1, 55, date ' 2015 - 05 / 05' Union double all the

Select option 2, 34, day ' 2015-06-04 Union double all the

Select option 2, 11, date ' double' 2015-05-08

)

Table_A_DEF (def_id, def_name) as)

Select 11, 'examine' from dual union all

Select 34, 'definitionF' from dual union all

Select 50, 'DEFINITIONH' from dual union all

Select 55, "definitionN' from dual

)

Table_B (record_id, record_name) as)

Select 1, "record1" dual union all

Select 2, 'record2"dual union all

Select 3, 'registration' record3 of the double

)

Select record_id, record_name

of table_B

When there is)

Select null

from table_A

Join table_A_DEF

using (def_id)

where table_A.record_id = table_B.record_id

Record_id group

having max (def_name) to keep (last dense_rank command by date_A)

in ("examine", "definitionN")

)

;

-or-

Select record_id, record_name

of table_B

where record_id in)

Select record_id

from table_A

Join table_A_DEF

using (def_id)

Record_id group

having max (def_name) to keep (last dense_rank command by date_A)

in ("examine", "definitionN")

)

;

If you post in the forum SQL you will get probably more answers, however.

Kind regards

Bob

Tags: Database

Similar Questions

  • How can I change a 'Album' back to a 'folder '?

    How can I change a 'Album' back to a 'folder '?

    Hanover wrote:

    How can I change a 'Album' back to a 'folder '?

    This means that a "record" has been changed in an "album", which makes no sense at all.

    To simplify, you understand that the folders on your computer are the place where your media files are written on your hard drives.

    You don't understand what a 'album' is. It is only a list of files in a particular order. An album does contain not any file (they are on your disk files), it's just a list, similar to a "playlist" for audio files. The albums are stored in the catalog.

    There is way to create an album by selecting the files in the organizer and eventually they sort in the order you want. You can create several albums containing a file: the file will not be duplicated, only a link to its unique location is enrolled in the various "albums". Deleting files in the list, deleting albums won't change anything for the real files.

    You can select the files to include in an album by individually selecting, selecting them by keyword or advanced search, or simply by selecting the files in a folder in the "Files" Panel It doesn't "change" files into albums.

    However, once you have an album, the organiser is able to select all the files and 'export as new files' in a new catalog empty. This duplication is the closest thing to the transformation of an album in a folder... (do not change back, though).

  • iTunes albums back reading

    A few weeks ago, all of a sudden, my songs started playing an order backward. When I play the first song from an album, itunes it identifies as something like the last song, and once the song is finished, playback ends. If I start playing the second song, and I press the 'next' button, it goes to the first song and the playback ends after that song. If I am in the opinion of the artist, and I have several albums of this artist, after the first song of an album, continues to play until the last song of the album.

    How can I fix? I'm under 12.2.2 itunes in Mac OS X Lion

    Thank you!

    Switch to the view of songs and make sure that you use an ascending sort order. You will find a small triangle at the top of the current sort column. Click this option to reverse the sort order. You should find playback now works too.

    TT2

  • 'Album' back field for compilations

    Hello, there is no way that I can view compilations in order to launch album year as the year of production of each track can be different decades of the release date of the compilation CD.  I recently asked Apple via iTunes comments they add a new field to ALBUM YEAR that can be filled manually.  If left blank, the default would be also present, the year on the latest track in the album.  In this way, all the individual songs can be sorted in the year they were recorded, and at the same time, all photos can be sorted in the year they were released.

    I have a large collection of over 32 000 titles for this level of sophistication of sorting is important to me. I went to the effort to have the correct year assigned to every single track in my collection, but this means compilations especially appear anywhere near their for grid album release date, when displayed in chronological order...

    If you accept this additional field is a good idea, please also submit a request for improvement of your comments to Apple via the iTunes application. Please copy and paste this content if you do not want to write your own presentation.

    I agree that it would be a useful improvement although I prefer to see an original release (a, m, j) date and edition release date.  However, all the iTunes data model metadata is unlikely to support this because it is not able to recognize 'album' as a primary concept - stands at the level of individual tracks, and it is these metadata that are used for the band's songs in albums in the presentation layer.

    As a solution, I use a somewhat esoteric pattern that fills the field of Sorting Album with a concatenation of (the most important artist of Sort Album Artist, artist, Genre artist and Album artist) with the date of album release in the format YYYYMMDD .  The result of this (if it is applied uniformly throughout a library) is that sort albums by artist and title really give a correct chronological list by artist and then by release date.

  • I want those last Pages back! I hate having to do it again when I get an automatic redirection page, because I can't choose how many pages I want to go back.

    V 3.6.17 has a drop down to the right of the back and next button called 'recent pages' bring BACK!

    When I go to a page that auto redirects me to another page, the only way to return to the page, I've been on before hand must be able to choose to return more than one page at a time. You who took in the most recent versions... If I could go back to this older version, I just for this feature.

    Calm down please. You cry for users (volunteers) like you who are trying to help.

    If you have rear arrow (s) in your Navigation bar, right-click on them and you will see your recent pages. You can also hold the left click for a second or two.

    There is an extension that restores the down marker if you feel that you need it-

    https://addons.mozilla.org/en-US/firefox/addon/backforward-dropmarker/?src=api.

    It is up to date.

  • last album with Active indicator 'Y' (if one only, select this account)

    Hi all

    I'll have a few records of emp table and must select a record by id, which meets following criteria: -.
    (1) if there is only one record for ID assigned, select them. EG - ' 0154 ', ' 0155'
    (2) If more than one record and then
    (2A) select the record with active_flag = 'Y '.
    (2B) If multiple records with the flag 'Y', select new album where flag = "Y". Max eff_date.


    Emp table: -.
    with emp as (
    select '0066' id, 'ABC' name, 'Y' active_flag, to_date('01-01-2009', 'dd-mm-yyyy') eff_date  from dual union
    select '0066', 'PQR', 'N', to_date('01-01-2010', 'dd-mm-yyyy') from dual union
    select '0066', 'XYZ', 'N', to_date('01-03-2010', 'dd-mm-yyyy') from dual union
    select '0154', 'PQR', 'N', to_date('01-05-2010', 'dd-mm-yyyy') from dual union
    select '0155', 'DEF', 'Y', to_date('01-05-2010', 'dd-mm-yyyy') from dual union
    select '8686', 'THY', 'N', to_date('01-10-2010', 'dd-mm-yyyy') from dual union
    select '8686', 'QWE', 'N', to_date('01-01-2010', 'dd-mm-yyyy') from dual union
    select '8686', 'POI', 'Y', to_date('01-04-2010', 'dd-mm-yyyy') from dual union
    select '8686', 'MNB', 'Y', to_date('01-03-2010', 'dd-mm-yyyy') from dual 
    ) 
    select * from emp;
    Output documents: -.
    with emp_selected as (
    select '0066' id, 'ABC' name, 'Y' active_flag, to_date('01-01-2009', 'dd-mm-yyyy') eff_date  from dual union
    select '0154', 'PQR', 'N', to_date('01-05-2010', 'dd-mm-yyyy') from dual union
    select '0155', 'DEF', 'Y', to_date('01-05-2010', 'dd-mm-yyyy') from dual union
    select '8686', 'POI', 'Y', to_date('01-04-2010', 'dd-mm-yyyy') from dual 
    ) 
    select * from emp_selected;
    Ask you to look at it please.

    Kind regards
    Ritesh

    Hello

    Something like:

    with emp as (
      select '0066' id, 'ABC' name, 'Y' active_flag, to_date('01-01-2009', 'dd-mm-yyyy') eff_date  from dual union
      select '0066', 'PQR', 'N', to_date('01-01-2010', 'dd-mm-yyyy') from dual union
      select '0066', 'XYZ', 'N', to_date('01-03-2010', 'dd-mm-yyyy') from dual union
      select '0154', 'PQR', 'N', to_date('01-05-2010', 'dd-mm-yyyy') from dual union
      select '0155', 'DEF', 'Y', to_date('01-05-2010', 'dd-mm-yyyy') from dual union
      select '8686', 'THY', 'N', to_date('01-10-2010', 'dd-mm-yyyy') from dual union
      select '8686', 'QWE', 'N', to_date('01-01-2010', 'dd-mm-yyyy') from dual union
      select '8686', 'POI', 'Y', to_date('01-04-2010', 'dd-mm-yyyy') from dual union
      select '8686', 'MNB', 'Y', to_date('01-03-2010', 'dd-mm-yyyy') from dual
    )
    select id, name, active_flag, eff_date
    from (
      select e.*,
             row_number() over( partition by id
                                order by case when active_flag = 'Y' then 0 else 1 end
                                       , eff_date desc ) rn
      from emp e
    )
    where rn = 1
    ;
    

    PS: Thanks for the very useful sample data in this way.

    Published by: odie_63 on March 3, 2011 15:43

  • last album of 6 months.

    I am a newcomer in the editor of 9 elements and is now trying to the Organizer.

    I deleted by mistake from the album "past 6 months".

    I guess that this a default album.

    How can I reinstall this album?

    Click on the sign under the word Albums and choose new smart album.

    Select the following settings, and then click OK.

    Click on the image to enlarge.

  • First of all, I got the last date to the top and the last date under the list of incoming emails, how do I get last date back to the top of the list is now all of a sudden

    I hope you understand what I mean, because English is not my language, but Dutch.

    Example: 17/11/2014

                    16-11-2014
                    15-11-2014   so I recieved my e mails and now
    

    15/11/2014
    16/11/2014
    17/11/2014

    and I want that the date of most recent entry up

    I hope that there is someone to help me.
    Thank you.

    Heinja

    Click the header to sort the column.

  • Suddenly cannot sync additional photo albums more Mac to iPhone

    Hi and thanks for reading!

    I use OS X 10.11.6 El Capitan on Macbook Pro with iTunes version 12.5.1 and just upgraded to iOS on iPhone 10.0.2 SE. There are 40 GB of storage available on the iPhone.

    All my photos are stored on my Mac and I always synchronize the albums selected using iTunes. Until today, I had nine albums (about 2000 pictures) synced to my phone. Just upgraded yesterday to iOS 10 and... cannot sync any additional album for my iPhone!   Do not help disable iTunes, Photos or even the iPhone and sync again. New pics added today to the former synchronized albums synchronizes all right.

    Is there a trick?  Or a problem of incompatibility between iOS 10 and iTunes 12.5.1?

    See you soon!

    LAO Bo

    Good news!  Problem solved!

    First of all, I noticed that on my iPhone, WeChat (a good Chinese software equivalent to Facebook x WhatsAp) saw my fine albums, while the pictures couldn't!

    So weird, that I was convinced to try once more to bring my old file Photos Cache in my photo library, even if a new cache file is supposed to be created whenever iTunes syncs photos.

    For some reason, the last time I tried it did not work, but this time he did: my old cache file was now in my photo library!  I don't know what I did differently.  In any case, I sync my photos once more with iTune then open the pictures on my iPhone, half hoping to find my old nine albums back... and here they were!  Even my two additional albums were there, with all the photos inside!

    Problem solved, even though I still don't know what it was. Looking at other positions in the community in respect of 'Synchronization of Photos with iOS10', it seems that iOS10 there a problem that requires a sort of library discount at zero.  Thank you Leonie bear with me and try to reproduce the problem on your computer!  Information guide me to the solution. And I'm very happy that I can wait a few months before moving to the Sierra...

    LAO Bo

  • Album artist vs artist

    I always found the hypothesis iTunes to sort on "Album Artisit' rather than 'Artist' to be incongruos.  If "Album Artist" is empty, as is likely (and is the historic norm than iTunes 7, I believe, when 'Artist album' for the first time), then sorting uses "artist."  Otherwise, it re-roots for "Album Artist".

    Since its inception, I spent hours - with great pleasure I would add - search and adding details of individual artists who are on a given track.  I still have them added under "Album Artist", leaving the 'artist' as it is.  It has allowined me to create playlists of many guitarists, saxophonists, drummers, bassists, etc... using the function "contains" in the smart playlists.

    It's great!  For example, it allows me to follow the career of a given artist.  Take the jazz guitarist, John McLaughln which has a remarkable and more versatile career and I was able to see the month here in Santiago of the Chile at the age of 74.  He played with all kinds of groups of albums and artists throughout his career, beginning with "Extrapoliation" in 1969 - "John McLaughlin, John Surman, John Odgers & Tony Oxley", Miles Davis the same year, heard on "The Complete in a Silent Way Sessions" with "Miles Davis, Wayne Shorter, Herbie Hancock, Chick Corea, Joe Zawinul, John McLaughlin, Dave Holland and Tony Williams. , and then in 1970 on "A handful of beauty" with Shakti - including "John McLaughlin, Zakir Hussain, Lakshminarayana Shankar and Vikku Vinayakram.  Then an advance for the 1984 revolutionary album "Friday Night in San Francisco with"Al Di Meola, Paco Lucia and John McLaughlin".» More recently (2008) on the album "Five Peace Band Live" with "Chick Corea, John McLaughlin, Kenny Garrett, Christian McBride and Vinnie Colaiuta", right through to his latest album which he and his band "The 4th Dimension" - "John McLaughlin, Gary Husband, Etienne me Bappe & Ranjit Barot" played here in the Chile last month.

    However, when I come to sort by "Artist" on my iPad or iPhone, I can not do or find 'John Mclaughlin & The 4th Dimension', as it automatically (although it is not the say - a product to sort my music by "Album Artist".

    "I'd love to alternate power between how I want spell -"Artist"or the artist of the Album '- and take advantage of this option as a simple option toggle in the configuration settings.  It is useful for others?  What to do for the next release?

    I think you use the artist and album back.  Artist album is the sort key field. If an album is X-band, but a track has been a guest there then the artist album should be X and the artist should be X with the exception of the a track where it is X with Y.  I would review how you do things and then make suggestions to Apple.  Realizing that he is a quite obscure request, so don't hold your breath.

    http://www.Apple.com/feedback/itunesapp.html

  • Update iTunes 12.0.4.119 does not sort by artist album?

    With the last iTunes update, all my compilations are now classified under V (for various artists), even though at least half of them are not compilations of real and I prefer that they are filed with the main artist.  For example, the last album tribute to George Harrison (George Fest), I have the compilation box checked and individual artists listed for each track.  However, in the artist field album, I put "Harrison, George (Various Artists)" while the album is ranked immediately after my albums of George Harrison.  Now she is mixed with because v that the iTunes update eliminated the ability to sort by album artist.  I'm missing something here, or should I wait for the next update and hope they add this back in?

    iTunes will sort albums separately if the indicator "the Album is a compilation...". "is checked.  Unless you use an iPod Classic or another older iDevice, you can clear this check box and simply use the Album artist tag as you describe.

  • Album does not save it properly; can't see status of backup in the preferences; cannot disconnect.

    I use PSE 9, currently on the Mac (moved from PES 9 on PC about two months ago). I noticed that the last album, which I have added to the PSE has yet the indication of backup head double arrow next to it, and these images are indeed not in my online account. Generally, this happened on my PC, as I click the account as in PES, enter my password and no matter what I would say that it was incorrect. I'd hit him then "disconnect", re - enter my credentials with the same password I had used, and the system would begin then successfully back up again.

    Unfortunately on the Mac, when I hit the "Sign out" link in the dialog box asking my password (after clicking on my link "welcome...") ("in PSE), he doesn't sign me out - he paused for 20-30 seconds with the color wheel, then just shows that I'm always connected. If I try to go to preferences-> backup, I get a message that there was a problem and I should re - open the preferences later. If I force the background backup process to stop by rt - by clicking on the icon in the Mac menu bar, it indeed closes correctly; However, when I reactivate it is PSE under preferences, as soon as I touched the checkbox, it tries to connect to my account online, and then gives me the same error saying I should «...» Close preferences and try again. »

    Can someone give me some advice as to why a) the backup in PSE 9 finally seems to fail and must be disconnected / reconnected b) why the "Déconnexion" link does not work, or why my password is not accepted within PSE only?

    Yes, I was able to connect via a browser (or same PES - just not the Organizer!) all this time and I use only about half of my space.

    I also posted on another forum PES and was directed to the solution - I had to remove the com Adobe.Pulse.plist file in my user library path and voila' I was able to connect inside the PSE Organizer and re - start the backup synchronization.  You don't know why the problem occurred, but this fixed!

  • Add an album of music from Apple which is not in the catalogue

    Hello

    I have the album Love, which has been made of the catalogue of the Beatles for the Cirque du Soleil show, there are some special and different mixtures of the fab4, but they have been downloaded completely wrong to Apple music, using existing songs of The Beatles. Is there a way I can choose to download the album, or re upload?

    Not at this stage. And Yes, the evil of matching has been a problem with Apple's music since the beginning.

    Before you start the instructions below - when you added the album to your library? Because it seems that Apple has improved their "alignment" lately. Still not perfect but better - then you want to just try to remove the album from your iTunes library (without deleting the tracks from your hard drive), and then adding the album in iTunes.

    If this does not work: you can try to trick music Apple (made with my albums by The Who). Rename the artist for this album as 'The Beatless' (I used "The Whoo"). Then, delete the songs in your library - but not from your hard disk. Go to the FILE menu in the top bar, and then select Add to library. Find the folder that has the love album titles and select it. iTunes will add the album back - allegedly under the name of the artist that you changed- and since it should not be able to match these tracks (Apple's music uses a logarithm using the name and title of follow the artist), you should download the track in your library.

    After you check that the appropriate versions are in your library - by checking on another device, not one who has the original tracks on it - you can then go back and change the name of the artist back. It should - at least he did for more than the WHO albums I tried this on--keep versions of love.

    In any case, I tried that a few versions of iTunes back - after reading about it here - and it worked for Live albums that I had by the Who.

  • R7000, problems with wireless connection after the last firmware update 1.0.6

    I recently updated to the latest firmware available for the R7000...

    The upgrade went well and my Wired PC all connected without any problem, but several of my wireless devices were unable to connect to the WiFi. I have my cell phone Wifi (Android phone) kept gives me an error of authentication, but was able to connect to the network comments... weird...

    I started firmware 1.0.4 and everything worked well again... it seems that the new firmware is buggy.

    The Firmware versions listed above are only for the first three issues, to save typing, but you get the version that I use...

    Nick

    Hello

    I would like to let you know, I've improved in 1.0.6 last night and everything worked. The difference is this time I had to reset my router to the factory settings using the reset hidden at the back button and hold the button for about 7-10 seconds. This resets the router to the factory settings. I then had to re-enter all my IP address reservations and the word block list, but all my wireless devices were able to connect. The last time I did the upgrade, I just restarted the router, and I had read that I had to do a factory reset to operate correctly.

    It would have been nice for Netgear arrive at a way to extract Information form my version last-place back... it would have saved me a lot of time...

    Good luck

  • Photos and my iPhoto imported events/albums

    Finally, I have to venture into the pictures and let it import my single iPhoto library.

    I have some Photos Version 1.2 (340.4.0)

    It has imported very well, but I have problems with the Albums which existed in iPhoto and are now submerged under "iPhoto events."

    I wish they were at the highest level in my last album, but can't see how. Of course, I didn't dare attempt to remove the "iPhoto events" where all things goes.

    Advice, please.

    The albums iPhoto events are standard albums, which can be moved to different folders like all other albums.

    If you have not yet revealed the sidebar with a list of the albums, reveal her pressing ⌥⌘S (command-option-S).

    You can easily drop off your albums at a different place in the list of albums.

Maybe you are looking for