Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Query to find Unique Records

Query to find Unique Records

Scheduled Pinned Locked Moved Database
database
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sjs4u
    wrote on last edited by
    #1

    Hi, I am having 3 tables A,B,C table A:- AID date 23 01/25/2010 24 01/25/2010 table B: BID AID FileName date 1 23 1.doc 01/25/2010 1.00 AM 2 23 2.doc 01/25/2010 1.05 AM 3 23 3.doc 01/25/2010 1.06 AM 4 24 4.doc 01/25/2010 2.00 AM 5 24 5.doc 01/25/2010 2.01 AM table 3 BID Status 1 E 2 M 3 P 4 P 5 P Now I want Query that I want Unique number of records whos status is 'P' that is only Last file whos status is 'P' Means I want the following output AID FileName date status 23 3.doc 01/25/2010 1.06 AM P 24 5.doc 01/25/2010 2.01 AM P Thanks

    P 1 Reply Last reply
    0
    • S sjs4u

      Hi, I am having 3 tables A,B,C table A:- AID date 23 01/25/2010 24 01/25/2010 table B: BID AID FileName date 1 23 1.doc 01/25/2010 1.00 AM 2 23 2.doc 01/25/2010 1.05 AM 3 23 3.doc 01/25/2010 1.06 AM 4 24 4.doc 01/25/2010 2.00 AM 5 24 5.doc 01/25/2010 2.01 AM table 3 BID Status 1 E 2 M 3 P 4 P 5 P Now I want Query that I want Unique number of records whos status is 'P' that is only Last file whos status is 'P' Means I want the following output AID FileName date status 23 3.doc 01/25/2010 1.06 AM P 24 5.doc 01/25/2010 2.01 AM P Thanks

      P Offline
      P Offline
      Pranay Rana
      wrote on last edited by
      #2

      Try following query hope it will work for you select tablesA.AID AID,FileName,tablesA.date date,status from tablesA inner join ( SELECT FileName,BID,AID from tablesB where bid in (select max(bid) from tablesB group by aid) ) as b on tablesA.AID = b.AID inner join tablesC on b.BID = tablesC.BID

      S 1 Reply Last reply
      0
      • P Pranay Rana

        Try following query hope it will work for you select tablesA.AID AID,FileName,tablesA.date date,status from tablesA inner join ( SELECT FileName,BID,AID from tablesB where bid in (select max(bid) from tablesB group by aid) ) as b on tablesA.AID = b.AID inner join tablesC on b.BID = tablesC.BID

        S Offline
        S Offline
        sjs4u
        wrote on last edited by
        #3

        It works.... Great Thanks for your Help

        P 1 Reply Last reply
        0
        • S sjs4u

          It works.... Great Thanks for your Help

          P Offline
          P Offline
          Pranay Rana
          wrote on last edited by
          #4

          welcome

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups