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. What is wrong with my query?

What is wrong with my query?

Scheduled Pinned Locked Moved Database
questiondatabase
3 Posts 3 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
    samflex
    wrote on last edited by
    #1

    Greetings experts, when I run the following query, it correctly gives me all the records from tableA but all NULL values from tableB even though there are records in tableB. Any ideas what I am doing wrong?

              SELECT DISTINCT isnull(a.district\_combo,'Not available'), 
    			a.voter\_fname, 
    			a.voter\_mname, 
    			a.voter\_lname, 
    			a.voter\_suffix, 
    			COALESCE(a.str\_number,'')+' '+COALESCE(a.str\_name,'')+' '+COALESCE(a.str\_suffix,'')+' '+COALESCE(a.str\_apt,'') AS res\_addr, 
    			a.str\_city, 
    			a.state, 
    			a.str\_zip, 
    			COALESCE(a.mail\_str\_num,'')+' '+COALESCE(a.mail\_str\_name,'')+' '+COALESCE(a.mail\_srt\_suff,'')+' '+COALESCE(a.mail\_apt,'')+' '+COALESCE(a.mail\_city,'')+' '+COALESCE(a.mail\_state,'')+' '+COALESCE(a.mail\_zip,'') AS mail\_address, 
    			a.dob, 
    			b.\* FROM dbo.tableA a LEFT OUTER JOIN dbo.tableB b ON a.record\_id=b.record\_id
    
    Richard DeemingR Z 2 Replies Last reply
    0
    • S samflex

      Greetings experts, when I run the following query, it correctly gives me all the records from tableA but all NULL values from tableB even though there are records in tableB. Any ideas what I am doing wrong?

                SELECT DISTINCT isnull(a.district\_combo,'Not available'), 
      			a.voter\_fname, 
      			a.voter\_mname, 
      			a.voter\_lname, 
      			a.voter\_suffix, 
      			COALESCE(a.str\_number,'')+' '+COALESCE(a.str\_name,'')+' '+COALESCE(a.str\_suffix,'')+' '+COALESCE(a.str\_apt,'') AS res\_addr, 
      			a.str\_city, 
      			a.state, 
      			a.str\_zip, 
      			COALESCE(a.mail\_str\_num,'')+' '+COALESCE(a.mail\_str\_name,'')+' '+COALESCE(a.mail\_srt\_suff,'')+' '+COALESCE(a.mail\_apt,'')+' '+COALESCE(a.mail\_city,'')+' '+COALESCE(a.mail\_state,'')+' '+COALESCE(a.mail\_zip,'') AS mail\_address, 
      			a.dob, 
      			b.\* FROM dbo.tableA a LEFT OUTER JOIN dbo.tableB b ON a.record\_id=b.record\_id
      
      Richard DeemingR Online
      Richard DeemingR Online
      Richard Deeming
      wrote on last edited by
      #2

      If it's giving you null values from tableB, then there aren't any records in tableB which match a record in tableA using the join condition you've supplied.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • S samflex

        Greetings experts, when I run the following query, it correctly gives me all the records from tableA but all NULL values from tableB even though there are records in tableB. Any ideas what I am doing wrong?

                  SELECT DISTINCT isnull(a.district\_combo,'Not available'), 
        			a.voter\_fname, 
        			a.voter\_mname, 
        			a.voter\_lname, 
        			a.voter\_suffix, 
        			COALESCE(a.str\_number,'')+' '+COALESCE(a.str\_name,'')+' '+COALESCE(a.str\_suffix,'')+' '+COALESCE(a.str\_apt,'') AS res\_addr, 
        			a.str\_city, 
        			a.state, 
        			a.str\_zip, 
        			COALESCE(a.mail\_str\_num,'')+' '+COALESCE(a.mail\_str\_name,'')+' '+COALESCE(a.mail\_srt\_suff,'')+' '+COALESCE(a.mail\_apt,'')+' '+COALESCE(a.mail\_city,'')+' '+COALESCE(a.mail\_state,'')+' '+COALESCE(a.mail\_zip,'') AS mail\_address, 
        			a.dob, 
        			b.\* FROM dbo.tableA a LEFT OUTER JOIN dbo.tableB b ON a.record\_id=b.record\_id
        
        Z Offline
        Z Offline
        ZurdoDev
        wrote on last edited by
        #3

        As Richard mentioned, your join is dropping them out. Which means that there is no record_id in tableB that matches record_id in tableA.

        There are only 10 types of people in the world, those who understand binary and those who don't.

        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