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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Join Problem

SQL Join Problem

Scheduled Pinned Locked Moved Database
helpdatabase
4 Posts 4 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.
  • N Offline
    N Offline
    Nishad
    wrote on last edited by
    #1

    Hi I have 2 tables Table A and Table B I want to join these tables. The relation between these tables is RegNo The first table stores the Trudent details and second table is a history table The regNo in the first table is primary key and second table is forign key I want to Join all the data in the these two tables based on Date and Last updated time I want the result like the following pls help me to find a soln RegNo Name Class Date 12ABC ABC 10 3/2/2010 13ABC DCB 1 3/2/2010 14DFG DFG 12 3/2/2010 15FHG FHG 5 3/2/2010 16RTY RTY 8 3/3/2010 Table B Id RegNo LastUpdated 1 12ABC 3/2/2010 12:30 2 12ABC 3/2/2010 13:00 3 12ABC 3/2/2010 16:00 4 13BC 3/2/2010 12:00 Result RegNo Name Class LastUpdated 12ABC ABC 10 3/2/2010 16:00 13ABC DCB 1 3/2/2010 12:00 14DFG DFG 12 NULL 15FHG FHG 5 NULL

    M P M 3 Replies Last reply
    0
    • N Nishad

      Hi I have 2 tables Table A and Table B I want to join these tables. The relation between these tables is RegNo The first table stores the Trudent details and second table is a history table The regNo in the first table is primary key and second table is forign key I want to Join all the data in the these two tables based on Date and Last updated time I want the result like the following pls help me to find a soln RegNo Name Class Date 12ABC ABC 10 3/2/2010 13ABC DCB 1 3/2/2010 14DFG DFG 12 3/2/2010 15FHG FHG 5 3/2/2010 16RTY RTY 8 3/3/2010 Table B Id RegNo LastUpdated 1 12ABC 3/2/2010 12:30 2 12ABC 3/2/2010 13:00 3 12ABC 3/2/2010 16:00 4 13BC 3/2/2010 12:00 Result RegNo Name Class LastUpdated 12ABC ABC 10 3/2/2010 16:00 13ABC DCB 1 3/2/2010 12:00 14DFG DFG 12 NULL 15FHG FHG 5 NULL

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Here is an article [^]that will help you understand what you want

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • N Nishad

        Hi I have 2 tables Table A and Table B I want to join these tables. The relation between these tables is RegNo The first table stores the Trudent details and second table is a history table The regNo in the first table is primary key and second table is forign key I want to Join all the data in the these two tables based on Date and Last updated time I want the result like the following pls help me to find a soln RegNo Name Class Date 12ABC ABC 10 3/2/2010 13ABC DCB 1 3/2/2010 14DFG DFG 12 3/2/2010 15FHG FHG 5 3/2/2010 16RTY RTY 8 3/3/2010 Table B Id RegNo LastUpdated 1 12ABC 3/2/2010 12:30 2 12ABC 3/2/2010 13:00 3 12ABC 3/2/2010 16:00 4 13BC 3/2/2010 12:00 Result RegNo Name Class LastUpdated 12ABC ABC 10 3/2/2010 16:00 13ABC DCB 1 3/2/2010 12:00 14DFG DFG 12 NULL 15FHG FHG 5 NULL

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

        Hope below code will resolve you problem select a.regno, a.name , a.class, b.date from table a left outer join ( select * from tableb wehre id = (select max(id) from tablb group by regno)) b on a.regno = b.regno

        1 Reply Last reply
        0
        • N Nishad

          Hi I have 2 tables Table A and Table B I want to join these tables. The relation between these tables is RegNo The first table stores the Trudent details and second table is a history table The regNo in the first table is primary key and second table is forign key I want to Join all the data in the these two tables based on Date and Last updated time I want the result like the following pls help me to find a soln RegNo Name Class Date 12ABC ABC 10 3/2/2010 13ABC DCB 1 3/2/2010 14DFG DFG 12 3/2/2010 15FHG FHG 5 3/2/2010 16RTY RTY 8 3/3/2010 Table B Id RegNo LastUpdated 1 12ABC 3/2/2010 12:30 2 12ABC 3/2/2010 13:00 3 12ABC 3/2/2010 16:00 4 13BC 3/2/2010 12:00 Result RegNo Name Class LastUpdated 12ABC ABC 10 3/2/2010 16:00 13ABC DCB 1 3/2/2010 12:00 14DFG DFG 12 NULL 15FHG FHG 5 NULL

          M Offline
          M Offline
          masoumeh2010
          wrote on last edited by
          #4

          Hi, This query dose not answer because RegNo in Table_B in Id 4 dose not equal with RegNo with Table_A, But if it's correct this is answer select a.RegNo,a.Name,count(a.Class),b.LastUpdated from Table_A as a left join Table_B as b on a.RegNo=b.RegNo where (b.Id between 3 and 4 ) or (a.RegNo Not In('16RTY')and a.RegNo In('14DFG','15FHG')) group by a.RegNo,a.Name,b.LastUpdated

          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