To Get the earlier records in a table for a particular id neglecting the newer ones

Hi All,
I need to get the older records for a particular id rejecting the newer ones..My Scenarios is as follows..
ID      Result           Date
1        Pass             2015-01-01
1        Fail                2015-03-05
2       Pass                2014-06-07
2       Fail                  2015-02-02
My Output will be 
ID        Result              Date
1          Pass                2015-01-01
2          Pass                 2014-06-07
How can i achieve this....Thanks in advance

Please follow the basic Netiquette of all SQL forums for the past 35+ years on the Internet. Post DDL that follows ISO-11179 rules for data element names. You have no idea; you do not even know that DATE is a reserved word in SQL! Use industry standard
encodings (ISBN, UPC, GTIN, etc) and avoid needless dialect. Give clear specifications. Give sample data. Web need to see the keys and constraints, the DRI, etc.  80-95% of the work in SQL is in the DDL. 
If you do not know that rows are not records, fields are not columns and tables are not files, then you should not be posting. If your tables have no keys, you should not be posting. If you have not tried any DML yourself, you should not be posting. 
>> I need to get the older records [sic] for a particular product_id, rejecting the newer ones..My Scenarios is as follows.. <<
Now we have to do all your typing because of your bad manners. Thanks a lot. Here is a repair job. 
CREATE TABLE Inspections 
(product_id CHAR(5) NOT NULL,
 inspection_date DATE NOT NULL
PRIMARY KEY (product_id, inspection_date),
 inspection_result CHAR(4) NOT NULL
 CHECK (inspection_result IN ('pass', 'fail'))
INSERT INTO Inspections 
VALUES
('prod1', '2015-01-01', 'pass'),
('prod1', '2015-03-05', 'fail'),
('prod2', '2014-06-07', 'pass')
('prod2', '2015-02-02', 'fail'); 
Here is one way to do this: 
WITH X(product_id, inspection_date, inspection_result, first_inspection_date)
AS 
(SELECT product_id, inspection_date, inspection_result,
        MIN(inspection_date) OVER (PARTITION BY product_id) 
   FROM Inspections)
SELECT product_id, inspection_date, inspection_result
 FROM X 
WHERE first_inspection_date = inspection_date;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • Hi i haven't updated my iDVD seen 2005 and to get the new one i need 7.0.4 first and i downloaded it from the apple website and when i go into the updating process its says "An eligible iDVD application was not found in the location /Applications." why"

    Hi i haven't updated my iDVD seen 2005 and to get the new one i need 7.0.4 first and i downloaded it from the apple website and when i go into the updating process its says "An eligible iDVD application was not found in the location /Applications." why

    Because you need to buy iLife 08 or newer on DVD first. If you're using iDVD 05, you probably have a PowerPC Mac and can't use iLife 11.
    (69573)

  • The on/off button on my 6th gen iPod nano recently got spoilt and I sent it back to the shop for a repair/exchange a week ago. Now I have just found out about the new 7th gen iPod nano and I am wondering, can I get the new one as a replacement?

    The on/off button on my 6th gen iPod nano recently got spoilt and I sent it back to the shop for a repair/exchange a week ago. Now I have just found out about the new 7th gen iPod nano and I am wondering, can I get the new one as a replacement?

    No.  You can turn your 6G Nano in to be recycled at your local Apple Store for a 10% discount towards the purchase of a new one. Otherwise, your only other option would be to sell the iPod on Craigslist or eBay and use the proceeds from the sale towards the purchase of the new 7G nano.
    B-rock

  • Now i can give my wife my old iphone and i will get the new one

    both of us will be very happy...thanks apple...win win...peace
    rastafari
    and no i do not feel apple screwed me over by making improvements on their product...EVERYONE knew this was coming and made the decision because they needed it the way it worked as a 2g phone...and for all we know the 3g may have a flaw and the old phones will be hot commodities...

    Ummm--you're taking the new phone (from what I can gather from your post) and giving your wife the old phone. HOW IS SHE GETTING A PHONE THAT COSTS "a couple hundred less"?????
    YOU ARE GETTING A CHEAPER PHONE...she's just getting your "cast-off".
    It's nice that you're giving your wife your "old" phone...but it's not special and you shouldn't feel especially proud. If you didn't have a wife...what would you do with this phone when you get the new one?

  • How can i get a damaged IMac just delivered replaced for free? How long will it take to get the new one?

    I just unwrapped my new iMac just being delivered by UPS and after removing all the wrapping I noticed deep scratches on the aluminium front and a big dent on the metal frame surrounding the screen. Obvioulsy it fell in the Apple assembly process or a heavy thing fell on it. I am so crossed as it took already 7 days to arrive and I now need to spend time trying to get it replaced one way or another, I believe this will take weeks before I get a replacement iMac and I am not sure in which state this new one will arrive. Very frustrating experience. I am hesitating to cancel the whole thing.

    IF you bought it from apple, you can bring it back to apple for a full refund or exchange. You can also call apple support to request for a mail-in box so you can return the item. if on the other hand it is an apple authorize reseller, kindly contact them for exchange/refund. They will give you an option on whether they will give you a label to help you send back the item to them or take it to the store.

  • Guys so there is a new itouch so i can surrender my old broken glass itouch to get the new one right??

    guys so there is a new itouch right?? can i surrender/trade my old broken glass itouch to get the new itouch that been out the market right? it will be discounted in half if i trade it in the apple store?.is right??

    Of course not.  Why would you think this?
    Apple will give you a 10% discount on a new ipod if you bring in an old cone for recycling.

  • Query to get the last added record in a table for a particular id

    T
    Hi,
    I have 2 tables A, B
    Table A has id,name
    Table B had parentid(foreignkey referring to ID in above table), record_type,created_timestamp
    I want to get the last added record_type from Table B for all the ids present in Table A.

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. I know this is
    a skeleton, but could you at least try to do good programming? Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. And sample data also helps. 
    I have 2 tables: Alphas, Betas
    CREATE TABLE Alphas
    (alpha_id CHAR(10) NOT NULL PRIMARY KEY,
     alpha_name VARCHAR(25) NOT NULL);
    Why was that DDL so hard you could not write it? But your narrative about the second table does not tell us if it has a key. I will guess that it is also alpha_id, but thanks to your rudeness, that is all we can do. 
    CREATE TABLE Beta 
    (alpha_id CHAR(10) NOT NULL PRIMARY KEY
       REFERENCES Alphas (alpha_id),
     record_type CHAR(2) NOT NULL,
     creation_timestamp DATETIME2(0) DEFAULT CURRENT_TIMESTAMP
          NOT NULL,
    >> I want to get the last added record_type from Table Beta for all the ids present in Table A.<<
    Think about this. Since Beta.alpha_id is a FOREIGN KEY to Alphas, all of its rows will have a match to Alpha. The SQL engine does this for you! 
    SELECT *
    FROM (SELECT alpha_id, record_type, creation_date,
                  MAX(creation_date) OVER () AS creation_date_max
            FROM Betas)
    WHERE creation_date = creation_date_max;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • If you replace an ipad 2, will you get the new one?

    Just wondering

    Perhaps so.  My Dad experienced the same with his iMac.  That being said, I suspect both are very unusual circumstances and I've never heard that done with any iOS device.  I have heard much of the opposite... people always get the exact replacement.  In any case, the user should not expect a 'free upgrade' as it's only very remotely possible.

  • Can I cancel an annual (not prepaid) subscription to get the new one for Black Friday?

    I am currently subscribed to the Student edition of Adobe CC, and would like to cancel it in order to get the Black Friday price. I'm assuming I'll have to contact customer service from here on out?
    Sara

    Hi Sara
    Please contact support for advice:  Contact Customer Care
    Thanks
    Bev

  • I got a brand new iPod Touch but I'd like to know if I could exchange or return it so I can get the new one. It has no scratches and hasn't been dropped.

    I want to know if this is possible. I'd obviously pay what's left for the newer version, but I don't even know if this is possible. Again, my iPod has zero scratches, hasn't been dropped, brand new. I had a case on it the whole time. Please reply! Thank you.

    Try:                                               
    - iOS: Not responding or does not turn on           
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - Try another cable       
    - Try on another computer                            
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
    Apple Retail Store - Genius Bar                                     

  • I bought a macbook pro a month ago and didnt know there was a better/newer model (macbook pro retina) - can I upgrade/take back my macbook and get the new one?

    When they told me about it I just thought it had a better display and decided it didn't bother me if the resolution was better, not knowing that it was thinner, has a HDMI connection, etc.
    I bought my macbook pro 13 inch exactly a month ago tomorrow. If I go back and tell them this will I be able to upgrade my laptop? I paid more than $1300 or something for this one, I'd be willing to pay up to the price of the retina model, do you think I'd be able to do this?

    mende1 wrote:
    peter_watt wrote:
    If your non retina MBP has a dvd slot and a large capacity conventional hard drive, you might find the retina model would have been less convenient with lower capacity SSD and no DVD.
    On the other hand, the MacBook Pro with Retina display has got a much faster drive and you can get an external DVD drive (not everybody needs a DVD drive)
    Absolutely, like I say personal Choice.  I believe from remarks in here that the SSD boots up on Mavericks in something like 10 seconds whereas mine takes even longer to boot than in Mountain Lion. But then we are advised to use sleep over boot as much as possible.  My problem is I have 300GB of stuff and getting bigger, and when I bought mine the biggest SSD was 250 I think. For me the choice of replaceable RAM vs soldered-in RAM was a clincher.

  • When is there a new macbook pro range to be launched? Im waiting to get the new one for my birthday.

    ??

    Apple has not announced a new Mac Pro so no one on here knows what Apple's plans might be.  The CEO hinted at a new Mac Pro in a presentation but nothing definitive has been said so far.

  • Cannot access my new emails after 2/16/15 in my inbox--why not and how can I get the new ones I know I have?

    Somehow the internet and my phone crashed. Called Vonage who reset everything so both phone and internet work, but I have lost emails after 2/16/15.

    http://kb.mozillazine.org/New_messages_do_not_appear

  • Can i get the new iPod Touch with out the camera?

    I was just wondering if i could get the iPod Touch 5th Gen with out the camera... i work in Puget Sound Naval Shipyard in Bremerton, WA and we are not allowed to have cameras in the work area, i have an ipod touch but i think it is only 2nd gen, if i could get the new one with out the camera that would be awesome

    falkirks wrote:
    No you can't and the 3rd gen has no camera and can run iOS 6
    I don't believe that's correct. The 3rd gen Touch cannot run iOS 6.
    See iOS 6 is compatible with at the bottom of this page; http://www.apple.com/ios/whats-new/. The 3rd gen Touch is not listed.

  • Just i received iphone 4S, earpod can't insert with the iphone. Becuase of the hole was slope. Can i claim that with the new one.

    I ordered online iphone 4S (Red Fri). Recently i received and found that can not insert earpod. Due to the hole of iphone was quite slop. There are 2 question. First i can claim the iphone. And second one is how long i get the new one.   

    if it's under warrenty and they judge that it was a defect from the build not something the user made by mistreating then yes

Maybe you are looking for

  • 25 gb of photos in phone but 13 gb in itunes

    First I've been trying to fix the 13 gb of other on my iphone, until i realized the amount of memory for my photos shown in the usage menu differed than the itunes bar. On my phone it says 25.5gb under camera roll whilst itunes says to have 13.54. My

  • How disable the full screen option in the standard or wireframe video player ?

    I was wondering if (and how) it's possible to just disable the full screen option in the controls that appear below the video player (standard or wireframe). I want to have a video player with the progression bar, play / pause options, the counter wi

  • A few problems using beans.....

    Where to start... Well, I have got a servlet that creates a new instance of a bean ('generalBean'), then the 'generalBean' runs a query within the DB it connects to. Then 'while(resultSet.next)' it creates an instance of another bean called 'detailed

  • How to get Itunes back to functionality

    My Itunes was regularly freezing when I added any type of file to my library. To fix this problem, I followed the steps to enter Safe Mode. While it did work, the steps afterwards to lead me to my Plugins and 3rd party software were futile, as openin

  • How change web link for help?

    Hi experts, I need to change help link in web in SRM 4.0. For example  http://x.com/support to http://y.com/support. Can you please help me with it step by step? Thanks in Advance.