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. writing a query to find table entries that have no records in related table

writing a query to find table entries that have no records in related table

Scheduled Pinned Locked Moved Database
databasehelp
6 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.
  • M Offline
    M Offline
    Michael J Eber
    wrote on last edited by
    #1

    I have a simple problem with a not-so-simple query (for me) to write. I have table A with has a single related table B. The relationship between A and B is a 1 : many I need a query the selects all rows in A that have nothing in B. I tried doing a query using Count(1) from B but I just cannot figure out the correct syntax to get a working query. Appreciate it if the SQL Gurus can help. Thanks

    D P C 3 Replies Last reply
    0
    • M Michael J Eber

      I have a simple problem with a not-so-simple query (for me) to write. I have table A with has a single related table B. The relationship between A and B is a 1 : many I need a query the selects all rows in A that have nothing in B. I tried doing a query using Count(1) from B but I just cannot figure out the correct syntax to get a working query. Appreciate it if the SQL Gurus can help. Thanks

      D Offline
      D Offline
      Dr Walt Fair PE
      wrote on last edited by
      #2

      Not sure exactly what you're trying to do but perhaps something of this form could help? SELECT * FROM A WHERE NOT EXISTS (SELECT * FROM B WHERE A.x=B.y)

      CQ de W5ALT

      Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

      M 1 Reply Last reply
      0
      • D Dr Walt Fair PE

        Not sure exactly what you're trying to do but perhaps something of this form could help? SELECT * FROM A WHERE NOT EXISTS (SELECT * FROM B WHERE A.x=B.y)

        CQ de W5ALT

        Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

        M Offline
        M Offline
        Michael J Eber
        wrote on last edited by
        #3

        Your query did the job. Thank you. As to "what I'm trying to do" I have one customer group creating the entries in table A. I have a second ops group out on the floor that creates the entries in table B. The second group needs to know all setups that have not been setup on the floor. Thus the query.

        D 1 Reply Last reply
        0
        • M Michael J Eber

          Your query did the job. Thank you. As to "what I'm trying to do" I have one customer group creating the entries in table A. I have a second ops group out on the floor that creates the entries in table B. The second group needs to know all setups that have not been setup on the floor. Thus the query.

          D Offline
          D Offline
          Dr Walt Fair PE
          wrote on last edited by
          #4

          Glad it worked. I've done similar queries to find out where data, etc. is missing.

          CQ de W5ALT

          Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

          1 Reply Last reply
          0
          • M Michael J Eber

            I have a simple problem with a not-so-simple query (for me) to write. I have table A with has a single related table B. The relationship between A and B is a 1 : many I need a query the selects all rows in A that have nothing in B. I tried doing a query using Count(1) from B but I just cannot figure out the correct syntax to get a working query. Appreciate it if the SQL Gurus can help. Thanks

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            See this[^] thread from yesterday.

            1 Reply Last reply
            0
            • M Michael J Eber

              I have a simple problem with a not-so-simple query (for me) to write. I have table A with has a single related table B. The relationship between A and B is a 1 : many I need a query the selects all rows in A that have nothing in B. I tried doing a query using Count(1) from B but I just cannot figure out the correct syntax to get a working query. Appreciate it if the SQL Gurus can help. Thanks

              C Offline
              C Offline
              CitrusTech
              wrote on last edited by
              #6

              You might also want to look at an outer join. I wrote something about this a while back: http://www.citrustechnology.com/blog/20100113

              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