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. select command..

select command..

Scheduled Pinned Locked Moved Database
databasehelp
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.
  • D Offline
    D Offline
    dansoft
    wrote on last edited by
    #1

    I want to add the names of the staffs, in the dropdownlist, who's login is not yet created. Eg. consider 2 tables staff, and login staffs: A,B,C,D,E login: B,E the logins are created for B and E so in the dropdownlist it must display A,C,D i tried the following query but it is not working. select sname from staff,login where staff.sname!=login.[name] It leads to duplicated records..... Please help!!

    M A T 3 Replies Last reply
    0
    • D dansoft

      I want to add the names of the staffs, in the dropdownlist, who's login is not yet created. Eg. consider 2 tables staff, and login staffs: A,B,C,D,E login: B,E the logins are created for B and E so in the dropdownlist it must display A,C,D i tried the following query but it is not working. select sname from staff,login where staff.sname!=login.[name] It leads to duplicated records..... Please help!!

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      You're using some very old join syntax there. The following should work for you:

      SELECT sname
      FROM staff
      LEFT JOIN login
      ON staff.sname = login.[name]
      WHERE [name] IS NULL

      How it works: the LEFT JOIN outputs all rows from the left-hand side joined to the right-hand side where the ON condition evaluates to true. If there is no match, it outputs the left-hand side row with NULLs in all the fields from the right-hand side. Because we want the rows which don't have a match, we select only the rows which have NULLs in the right-hand side. If we wanted only the rows that did match, I'd use an INNER JOIN. That gives only rows where the ON condition evaluates to true. Stability. What an interesting concept. -- Chris Maunder

      1 Reply Last reply
      0
      • D dansoft

        I want to add the names of the staffs, in the dropdownlist, who's login is not yet created. Eg. consider 2 tables staff, and login staffs: A,B,C,D,E login: B,E the logins are created for B and E so in the dropdownlist it must display A,C,D i tried the following query but it is not working. select sname from staff,login where staff.sname!=login.[name] It leads to duplicated records..... Please help!!

        A Offline
        A Offline
        albCode
        wrote on last edited by
        #3

        select staff.* , login.* from staff,login where staff.sname <> login.name Proud to be Albanian

        1 Reply Last reply
        0
        • D dansoft

          I want to add the names of the staffs, in the dropdownlist, who's login is not yet created. Eg. consider 2 tables staff, and login staffs: A,B,C,D,E login: B,E the logins are created for B and E so in the dropdownlist it must display A,C,D i tried the following query but it is not working. select sname from staff,login where staff.sname!=login.[name] It leads to duplicated records..... Please help!!

          T Offline
          T Offline
          turbochimp
          wrote on last edited by
          #4

          This will also work, if I understand your question correctly (i.e. you want to know what staff members do not have a corresponding record in the login table):

          SELECT
              s.sname
          FROM
              staff s
          WHERE
              s.sname NOT IN (SELECT name FROM login)
          

          or this...

          SELECT
              s.sname
          FROM
              staff s
          WHERE
              NOT EXISTS (SELECT 1 FROM login l WHERE l.name = s.sname)
          

          The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

          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