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. left outer join - question

left outer join - question

Scheduled Pinned Locked Moved Database
question
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.
  • E Offline
    E Offline
    ensger
    wrote on last edited by
    #1

    Hello, I have two tables, A like number, value1 value2, and B like number, aktiv, value2, ... As I want to have all lines of table A, even number does not exist in table B I made a command 'select from A left outer join B on A.number = B.number' Works fine, but if I try "where B.aktiv != '-1'", the NULL-Values also disapears. I also tried "(where B.aktiv = '1') or (B.aktiv = NULL)" - it doesn't work. What am I doing wrong? Thanks, Gerhard

    R R 2 Replies Last reply
    0
    • E ensger

      Hello, I have two tables, A like number, value1 value2, and B like number, aktiv, value2, ... As I want to have all lines of table A, even number does not exist in table B I made a command 'select from A left outer join B on A.number = B.number' Works fine, but if I try "where B.aktiv != '-1'", the NULL-Values also disapears. I also tried "(where B.aktiv = '1') or (B.aktiv = NULL)" - it doesn't work. What am I doing wrong? Thanks, Gerhard

      R Offline
      R Offline
      Rob Graham
      wrote on last edited by
      #2

      NULL cannot be compared to any value, so it is neither = -1 of != -1 or even =Null. If you need to find NULL values you must use IS NULL (Where B.aktiv IS NULL) NOTE: If you turn the ANSI_NULLS option off, Transact SQL will return comparisons for null, SEE Books Online for more info.

      1 Reply Last reply
      0
      • E ensger

        Hello, I have two tables, A like number, value1 value2, and B like number, aktiv, value2, ... As I want to have all lines of table A, even number does not exist in table B I made a command 'select from A left outer join B on A.number = B.number' Works fine, but if I try "where B.aktiv != '-1'", the NULL-Values also disapears. I also tried "(where B.aktiv = '1') or (B.aktiv = NULL)" - it doesn't work. What am I doing wrong? Thanks, Gerhard

        R Offline
        R Offline
        Ritwik Sanyal
        wrote on last edited by
        #3

        It seems that columns having NULL values in B.aktiv is getting eliminated. You can try the following: - WHERE ISNULL(B.aktiv,1)!='-1' Let me know if its working for you.

        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