SQL Query to retrieve records for all after the Max Dates.

Hello everyone,

I am trying to retrieve the record more recent, based on the date field ( nextDate ).

Currently, there are only 4 records in the MC_Maintenance table and two in the Machine table.

Machine table

MC_id             EquipID          

1                      0227

MC_id EquipID

2                     0228

---------------------------------

MC_Maintenance table

Maint_id MC_id Next_maint

1                      2                      08/25/2010     

2                      2                      07/01/2010

3                      1                      2010-11-06

4                      1                      07/11/2010

I have am trying to accomplish is,.

the list of the two machines of the table of the Machine with the MAX (Next_maint) control the list of MC_Maintenance results

These are the records I want to display.

Maint_id MC_id Next_maint

1                      2                      08/25/2010

4                      1                      07/11/2010                 

Here is the SQL query

SELECT

       MC. MC_ID as ID,

MC.complete_Date completed.

MC.next_maint as nextDate,.

MC.maint_notes as noted,.

MC.facility Facility.

M.EquipId,.

$m.name as the name.

M.SerialNumber SN.

M.dept as dept.

M.Freq as freq

Of MC_Maintenance MC, Machine M

        where  MC. MC_ID = M.MC_ID

'           Using MAX (nextDate)

Any ideas would be useful.

TJ

I thought it was a simple group of problem?

SELECT M.EquipID, MC.MC_ID, Max(MC.next_maint)
FROM MC_Maintenance MC INNER JOIN Machine M ON MC.MC_ID = M.MC_ID
GROUP BY M.EquipID, MC.MC_ID

Tags: ColdFusion

Similar Questions

  • SQL Query to retrieve records in a table with the same records or only one record in a table

    Hello

    Got a curious requirment to extract the Non-distincts records in a table

    Example of

    Account number Type of account
    12345SB
    12345

    SB

    12346CR
    12346SB
    12347SB
    12348CR
    12349SB

    Requrirement is to retrieve the records as follows

    Result must be

    Account number Type of account
    12345SB
    12345

    SB

    12347SB
    12348CR
    12349SB

    You will notice that 12346 which has two separate lines have been eliminated in the result. I tried several qeries to achieve this result, one or the other had a few mismatch. Can someone give me a request for it.

    Thanks in advance.

    SELECT ACCOUNT_NUMBER,

    ACCOUNT_TYPE

    DE)

    SELECT ACCOUNT_NUMBER,

    ACCOUNT_TYPE,

    COUNT (*) ON CNT_ACC (ACCOUNT_NUMBER PARTITION).

    COUNT (*) ON CNT_NUM_TYP (PARTITION ACCOUNT_NUMBER, ACCOUNT_TYPE)

    FROM T1)

    WHERE CNT_ACC = CNT_NUM_TYP;

    exit;

    12345 SB
    12345 SB
    12347 SB
    12348 CR
    12349 SB
  • SQL query to retrieve a single record for each employee of the following table?

    Hi all

    Help me on the writing of SQL query to retrieve a single record for each employee of the following table? preferably a standard SQL.

    CREATE TABLE xxc_contact)

    empnum NUMBER,

    alternatecontact VARCHAR2 (100),

    relationship VARCHAR2 (10),

    phtype VARCHAR2 (10),

    Phone NUMBER

    );

    insert into xxc_contact values (123456, 'Rick Grimes', 'SP', 'Cell', 9999999999)

    insert into xxc_contact values (123456, 'Rick Grimes', 'SP', 'Work', 8888888888)

    insert into xxc_contact values (123457, 'Daryl Dixon', 'EN', 'Work', 7777777777)

    insert into xxc_contact values (123457, 'Daryl Dixon', 'EN', 'Home', 3333333333)

    insert into xxc_contact values (123456, 'Maggie Greene', 'CH', 'Cell', 9999999999)

    insert into xxc_contact values (123456, 'Maggie Greene', 'CH', 'Home', 9999999999)

    expected result:

    EmpNum AlternateContact Relationship PhType Phone       

    123456 rick Grimes SP cell 9999999999

    Daryl Dixon EN work 7777777777 123457

    Home 123458 Maggie Greene CH 6666666666

    Thanks in advance.

    994122 wrote:

    Thank you all, that I got a result

    http://www.orafaq.com/Forum/m/620305/#msg_620305

    By Lalit Kumar B...

    Specifically, the two simple solutions provided were:

    1 using the row_number, entitled Oracle ranking based on descending order of the inside telephone each empnum group. And finally selects the lines which has least rank (of least since that order is descending for phone).

    SQL > column alternatecontact format A20;

    SQL >

    SQL > SELECT empnum, alternatecontact, relationship, phtype, phone

    2 from (SELECT a.*, row_number() over r (PARTITION BY empnum ORDER BY phone / / DESC))

    3 FROM xxc_contact one)

    4. WHEN r = 1

    /

    EMPNUM ALTERNATECONTACT RELATIONSHIP PHTYPE PHONE

    ---------- -------------------- ---------- ---------- ----------

    123456 rick Grimes SP cell 9999999999

    Daryl Dixon EN work 7777777777 123457

    Home 123458 Maggie Greene CH 6666666666

    2. with the help of MAX, Oracle automatically assigns the maximum phone for all the rows in each group of empnum. And finally selects the rows with the maximum phone. Order by clause is omitted here intentionally. You can find out why.

    SQL > SELECT empnum, alternatecontact, relationship, phtype, phone

    2 (SELECT a.*, MAX (phone) over (PARTITION BY empnum) rn FROM xxc_contact one)

    3 WHERE phone = rn

    4.

    EMPNUM ALTERNATECONTACT RELATIONSHIP PHTYPE PHONE

    ---------- -------------------- ---------- ---------- ----------

    123456 rick Grimes SP cell 9999999999

    Daryl Dixon EN work 7777777777 123457

    Home 123458 Maggie Greene CH 6666666666

    Kind regards

    Lalit

  • SQL query to retrieve only numbers to a string variable

    Dear all Experts,

    I have a requirement in one of my projects where I need to extract only the numbers present in the variable.

    for example:

    BANK_ACCOUNT_NUMBER = 12345-67890';

    BANK_ACCOUNT_NUMBER = 12345 67890';

    BANK_ACCOUNT_NUMBER = "123.456.7890";

    BANK_ACCOUNT_NUMBER = 123-A456BC7890D';


    In all these cases, I need to retrieve only numbers such as BANK_ACCOUNT_NUMBER = 1234567890 and I am looking for SQL query only.


    Please suggest me the query how to extract numeric values from varchar variable.



    Thank you

    Knockaert

      select regexp_replace('123-A456BC7890D','[^0-9]') from dual;
    

    See you soon,.

    Manik.

  • SQL query client fetch that has all the products

    Hi all

    I need a SQL query to retrieve the output as shown

    Table: ACCOUNT_SUMMARY

    prod_id Cust_id

    101 AAA

    BBB 101

    101. THE CCC

    102 AAA

    103 AAA

    102. THE CCC

    : Table

    Prod_id Prod_desc

    101 Home_loan

    Vehicle loan 102

    Loan education 103

    Expected results:

    Cust_id Prod_desc

    AAA Home_loan

    AAA auto loan

    Educational ready AAA

    Sorry, could not understand your question clearly.

    Do you want this:

    WITH account_summary
                      AS (SELECT 101 prod_id,'AAA' cust_id FROM dual UNION ALL
                          SELECT 101,'BBB' FROM dual UNION ALL
                          SELECT 101,'CCC' FROM dual UNION ALL
                          SELECT 102,'AAA' FROM dual UNION ALL
                          SELECT 103,'AAA' FROM dual UNION ALL
                          SELECT 102,'CCC' FROM dual)
        ,Product
              AS (SELECT 101 prod_id,'Home_loan' prod_desc FROM dual UNION ALL
                  SELECT 102,'Vehicle loan' FROM dual UNION ALL
                  SELECT 103,'Educational Loan' FROM dual
                  )
      , acc_count
          AS  (SELECT prod_id, cust_id ,count(*) OVER (PARTITION BY cust_id) cnt
                FROM account_summary
                )
    SELECT A.prod_id,P.prod_desc
    FROM acc_count A, product P
    WHERE A.prod_id = P.prod_id
    AND  cnt = (SELECT count(*) FROM product)
    ORDER BY A.prod_id
    
  • Jerky mouse mouseover function for all while the menu (file, options, help) and the key back/forward/home too. More scrolling is choppy every Web site.

    Jerky mouse mouseover function for all while the menu (file, options, help) and the key back/forward/home too. More scrolling is choppy every Web site since the update to version 3.6 to 4 RC1.

    Gel mouse pointer when it comes across objects that use some sort of animation or gradual highlighting when hovering on (which is basically all the Firefox 4 items menu, tabs, etc.) But also a lot of things on the Web pages as the green buttons on this page that change color when you hover over them).

    After rebooting my system, however, the problem seems to have disappeared!

    [, WinXP SP3 - 4 GB RAM, Core i5 M520, driver Nvidia NVS3100M 6.14.12.5738, Firefox 4.0]

  • I have Windows vista Ultimate edition. but he started asking for activation after the windows update while it has already been activated before the update.

    I have Windows vista Ultimate edition. but he started asking for activation after the windows update while it has already been activated before the update.

    Hello, Pichon,

    If Windows Vista application unexpected activation

    On rare occasions, you may be prompted to activate Windows Vista on a computer that did not previously require Windows Vista activation or has already been activated successfully. For example, this may occur on a computer on which Windows Vista was preinstalled by an OEM installation or Volume licensing and are major hardware changes occurred, such as upgrading the hard disk and memory at the same time.

    If you are prompted to reactivate Windows Vista, you can do this by using the Windows Activation Wizard to:

    1. Click Start, and then click computer.
    2. Click System Properties on the toolbar, and then click click here to activate Windows now in the Windows activation area. If you are prompted for an administrator password or a confirmation, type the password, or click continue.
    3. Select the Windows Vista activation method that you want, and then follow the instructions.

    To avoid this problem in the future, obtain the latest service pack for your version of Windows Vista, either through automatic updates or direct download.

    To update to Windows Vista and prevent this activation problem does not happen:

    1. Click Start, click all programs, and then click Windows Update.
    2. Click find updates.
    3. As soon as Windows Vista found the updates, click the install updates button.

    How to activate Windows Vista

    http://support.Microsoft.com/kb/940315

    Activation fails when you try to activate Windows Vista, Windows 7, Windows Server 2008 or Windows Server 2008 R2 on the Internet

    http://support.Microsoft.com/kb/921471

  • Vista goes to 50% CPU usage and connects the computer for hours after the beginning

    Original title: Vista processor

    Stupid Vista goes to 50% CPU usage and connects the computer for hours after the start.  Cannot run anything with any request of CPU without getting bogged down and crashing.  It is not windows defender, I suspend this service and the machine is ok for another 1/2 hour, them I'm up to 50% of the CPU.  The idle process said Task Manager is > 90%, still indicates 50% CPU usage and the cooling fan looks like a 747 taking off.  Should I just pull the machine and go for Linux, or what?  Cannot run games or whatever it is, totally disgusted with vista of POS and microsoft can it Deep and do not get windows 7, it is probably worse.  Is that all I can turn off to get the same performance than, say, windows 3.1?  It would be preferable to the current situation.  MSCKMA.

    Hello

    What antivirus/antispyware/security products do you have on the machine? Be one you have NEVER
    on this machine, including those you have uninstalled (they leave leftovers behind which can cause
    strange problems).

    ----------------------------------------------------

    Follow these steps:

    Start - type this in the search box-> find COMMAND at the top and RIGHT CLICK – RUN AS ADMIN

    Enter this at the command prompt - sfc/scannow

    How to analyze the log file entries that the Microsoft Windows Resource Checker (SFC.exe) program
    generates in Windows Vista cbs.log
    http://support.Microsoft.com/kb/928228

    Also run CheckDisk, so we cannot exclude as much as possible of the corruption.

    How to run the check disk at startup in Vista
    http://www.Vistax64.com/tutorials/67612-check-disk-Chkdsk.html

    ==========================================

    After the foregoing:

    How to troubleshoot a problem by performing a clean boot in Windows Vista
    http://support.Microsoft.com/kb/929135
    How to troubleshoot performance issues in Windows Vista
    http://support.Microsoft.com/kb/950685

    Optimize the performance of Microsoft Windows Vista
    http://support.Microsoft.com/kb/959062
    To see everything that is in charge of startup - wait a few minutes with nothing to do - then right-click
    Taskbar - the Task Manager process - take a look at stored by - Services - this is a quick way
    reference (if you have a small box at the bottom left - show for all users, then check that).

    How to check and change Vista startup programs
    http://www.Vistax64.com/tutorials/79612-startup-programs-enable-disable.html

    A quick check to see that load method 2 is - using MSCONFIG then put a list of
    those here.
    --------------------------------------------------------------------

    Tools that should help you:

    Process Explorer - free - find out what files, key of registry and other objects processes have opened.
    What DLLs they have loaded and more. This exceptionally effective utility will show you even who has
    each process.
    http://TechNet.Microsoft.com/en-us/Sysinternals/bb896653.aspx

    Autoruns - free - see what programs are configured to start automatically when you start your system
    and you log in. Autoruns also shows you the full list of registry and file locations where applications can
    Configure auto-start settings.
    http://TechNet.Microsoft.com/en-us/sysinternals/bb963902.aspx
    Process Monitor - Free - monitor the system files, registry, process, thread and DLL real-time activity.
    http://TechNet.Microsoft.com/en-us/Sysinternals/bb896645.aspx

    There are many excellent free tools from Sysinternals
    http://TechNet.Microsoft.com/en-us/Sysinternals/default.aspx

    -Free - WhatsInStartUP this utility displays the list of all applications that are loaded automatically
    When Windows starts. For each request, the following information is displayed: Type of startup (registry/Startup folder), Command - Line String, the product name, Version of the file, the name of the company;
    Location in the registry or the file system and more. It allows you to easily disable or remove unwanted
    a program that runs in your Windows startup.
    http://www.NirSoft.NET/utils/what_run_in_startup.html

    There are many excellent free tools to NirSoft
    http://www.NirSoft.NET/utils/index.html

    Window Watcher - free - do you know what is running on your computer? Maybe not. The window
    Watcher says it all, reporting of any window created by running programs, if the window
    is visible or not.
    http://www.KarenWare.com/PowerTools/ptwinwatch.asp

    Many excellent free tools and an excellent newsletter at Karenware
    http://www.KarenWare.com/

    ===========================================

    Vista and Windows 7 updated drivers love then here's how update the most important.

    This is my generic how updates of appropriate driver:

    This utility, it is easy see which versions are loaded:

    -Free - DriverView utility displays the list of all device drivers currently loaded on your system.
    For each driver in the list, additional useful information is displayed: load address of the driver,
    Description, version, product name, company that created the driver and more.
    http://www.NirSoft.NET/utils/DriverView.html

    For drivers, visit manufacturer of emergency system and of the manufacturer of the device that are the most common.
    Control Panel - device - Graphics Manager - note the brand and complete model
    your video card - double - tab of the driver - write version information. Now, click on update
    Driver (this can do nothing as MS is far behind the certification of drivers) - then right-click.
    Uninstall - REBOOT it will refresh the driver stack.

    Repeat this for network - card (NIC), Wifi network, sound, mouse, and keyboard if 3rd party
    with their own software and drivers and all other main drivers that you have.

    Now in the system manufacturer (Dell, HP, Toshiba as examples) site (in a restaurant), peripheral
    Site of the manufacturer (Realtek, Intel, Nvidia, ATI, for example) and get their latest versions. (Look for
    BIOS, Chipset and software updates on the site of the manufacturer of the system here.)

    Download - SAVE - go to where you put them - right click - RUN AD ADMIN - REBOOT after
    each installation.

    Always check in the Device Manager - drivers tab to be sure the version you actually install
    presents itself. This is because some restore drivers before the most recent is installed (sound card drivers
    in particular that) so to install a driver - reboot - check that it is installed and repeat as
    necessary.

    Repeat to the manufacturers - BTW in the DO NOT RUN THEIR SCANNER device - check
    manually by model.

    Look at the sites of the manufacturer for drivers - and the manufacturer of the device manually.
    http://pcsupport.about.com/od/driverssupport/HT/driverdlmfgr.htm

    How to install a device driver in Vista Device Manager
    http://www.Vistax64.com/tutorials/193584-Device-Manager-install-driver.html

    If you update the drivers manually, then it's a good idea to disable the facilities of driver under Windows
    Updates, that leaves about Windows updates but it will not install the drivers that will be generally
    older and cause problems. If updates offers a new driver and then HIDE it (right click on it), then
    get new manually if you wish.

    How to disable automatic driver Installation in Windows Vista - drivers
    http://www.AddictiveTips.com/Windows-Tips/how-to-disable-automatic-driver-installation-in-Windows-Vista/
    http://TechNet.Microsoft.com/en-us/library/cc730606 (WS.10) .aspx

    ===========================================

    Refer to these discussions because many more excellent advice however don't forget to check your antivirus
    programs, the main drivers and BIOS update and also solve the problems with the cleanboot method
    first.

    Problems with the overall speed of the system and performance
    http://support.Microsoft.com/GP/slow_windows_performance/en-us

    Performance and Maintenance Tips
    http://social.answers.Microsoft.com/forums/en-us/w7performance/thread/19e5d6c3-BF07-49ac-a2fa-6718c988f125

    Explorer Windows stopped working
    http://social.answers.Microsoft.com/forums/en-us/w7performance/thread/6ab02526-5071-4DCC-895F-d90202bad8b3

    Hope these helps.

    Rob Brown - MS MVP - Windows Desktop Experience: Bike - Mark Twain said it right.

  • should my time capsule be connected with a cable for backups, after the initial installation?

    should my time capsule be connected with a cable for backups, after the initial installation?

    If you mean that you have to keep your Mac connected to a Time Capsule via Ethernet for future backups, then the answer is no. Time Machine and time Capsule are designed to work over wireless for your Mac would just need to be connected to the wireless network provided by the time Capsule.

  • I made a record for microsoft in the 1980s for invision telephony. This is an online tutorial. There anywhere and if I can get a copy?

    I made a record for microsoft in the 1980s for invision telephony. This is an online tutorial. There anywhere and if I can get a copy?

    my friend told me he saw a long time ago on its computer-just my head talking in a small window on the screen. I remember that the script spoke of quality video, audio and synchronization...

    Hello

    I suggest looking in your favorite web browser and see if you can find the required records.

    I hope this helps.

  • How to keep the audit record for access to the Internet folder?

    Referring to the following link, I like to keep the audit record for access to the file from the Internet,

    Does anyone have suggestions on the option that I can put on this record?

    Thanks in advance for your suggestions

    http://support.Microsoft.com/kb/310399

    Hello

    You can follow this link & check if the problem persists:

    Monitor attempts to access and change settings on your computer

    Hope the helps of information.

  • Is legal to use "slmgr-rearm" extend using period in Windows 7 Ultimate & may I re-install Win 7 and use it for 30 days after the expiration date (29 days)?

    Hello
    I live in Iran.
    Here access to the original windows is not easy.
    I have ultimate edition (eternity) win 7.
    He let me to use during 30 days three times use "slmgr-rearm" to extend the trial period.
    Hereby, I can use and update.
    I have two questions.
    1. is legal to use "slmgr-rearm" extend with period?
    2-may I have reinstall win 7 and use it for 30 days after the expiration date (29 days)?

    with speciall thank you

    original title: Reinstall windows 7 ultimate

    According to the software Microsoft Windows 7 license, you must activate Windows 7 within 30 days of installation.  You are not allowed to circumvent or bypass the product activation.  After 30 days, you must enter a genuine Windows 7 product key for the edition you have installed, or remove Windows 7 by reformatting the hard drive, on which it is installed.

    In addition, you must respect Export Basics.

  • Can I get the videos for all of the concepts of photoshop learning?.

    I have an account paying adobe... Can I get the videos for all of the concepts of photoshop learning?.

    All I see is that links like

    CC Photoshop tutorials | Learn how to use Photoshop CC

    Above links are available even without an account.

    Should I have any extra advantage to access additional videos (as in lynda.com where they have the series of videos that explain how to do something with explanation of the concept)

    Originally, there was a selection of 'members only' videos on the Adobe Web site. But this project was abandoned and all content has been made public.

  • SIRS; have not been able to access CC 2015 for all day; the little dotted wheel starts to turn. Is there a problem?  Thank you

    SIRS; have not been able to access CC 2015 for all day; the little dotted wheel begins to turn without opening... Is there a problem?

    Does not open App | Wheels of progress turn continuously

    https://helpx.Adobe.com/creative-cloud/KB/creative-cloud-app-doesn ' t - open.html

  • Buy unlocked iPhone 7 right after the release date

    Friends good day! Let's say I want to buy an iPhone 7 right after the release date before apple officially begins selling the devices free SIM card. I'd be able to come simply to store and buy, for example, an AT & T phone to use with my operator? Because I know that they would be not selling sim free phones in the first two weeks. Or do I have to buy a plan as well and become a customer of AT & T? In other words, I need now a unlocked device, and can I get one without waiting for the start of the free features of SIM card sale. Thank you!

    If you buy any iPhone outright directly from Apple full paying, it is carrier unlocked.

Maybe you are looking for

  • Watch has been updated to read the voltage pressure (6/2016)?

    My doctor wants me to take my blood pressure every morning when I wake up.  Apple Watch this for me (from June 2016)? Since I've already paid for the watch and it reads my heart rate, the idea to buy another device to read blood pressure irks me - I'

  • SLurl proxy

    cant connet brower with slurl proxy how can I fix it?

  • Portege Z20t-C-121 screen does not automatically turn into tablet mode

    Hello We bought a Portege Z20t-C-121 to test as a replacement for some of our leaders. I have built with Windows 10 company and installed all the drivers latest on the Toshiba site. A WiFi Intel driver did not work properly so I downloaded and instal

  • Envy 15 k233ca: memory upgrades and hhd

    I'm trying to find out if the k233ca has a capacity of upgrade. By reading the plug here and there, the motherboard has 2 slots and there is 1 to 8 GB 1600 Mhz DDR3L module. When I called customer service to see if there was a favorite of the seller,

  • Bend contour (assistant vs labview vision)

    Hello In the Vision Assistant, if I use 'Analysis of Contour' and click on "Curvature of the computer", there is a table below that show x, position y as the value of the curvature. When I'm in LabVIEW, there is only a table out of the function of cu