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

SQL

Scheduled Pinned Locked Moved Database
database
7 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
    dev_rfid
    wrote on last edited by
    #1

    can i use a subquery field to my main query. i.e select x.field1,y.field2 from tbl1 as x where x.field3 not in (select y.field3 from tbl2 as y) :confused:

    M T 2 Replies Last reply
    0
    • D dev_rfid

      can i use a subquery field to my main query. i.e select x.field1,y.field2 from tbl1 as x where x.field3 not in (select y.field3 from tbl2 as y) :confused:

      M Offline
      M Offline
      Michael Potter
      wrote on last edited by
      #2

      Yes, do be aware that a 'not in' query can be very lengthy if your tables are large.

      D 1 Reply Last reply
      0
      • M Michael Potter

        Yes, do be aware that a 'not in' query can be very lengthy if your tables are large.

        D Offline
        D Offline
        dev_rfid
        wrote on last edited by
        #3

        thanks, than what can i do ? :confused:

        M 1 Reply Last reply
        0
        • D dev_rfid

          thanks, than what can i do ? :confused:

          M Offline
          M Offline
          Michael Potter
          wrote on last edited by
          #4

          Sorry - didn't see your reference of y.field2 in the SELECT. Your original query will not work. You can try a left join:

          SELECT 
              x.field1,
              y.field2 
          FROM 
              tbl1 x
          LEFT JOIN 
              tbl2 y
              ON (x.field3 = y.field3)
          WHERE 
              y.field2 IS NULL
          

          -- modified at 14:37 Friday 10th February, 2006

          D 1 Reply Last reply
          0
          • D dev_rfid

            can i use a subquery field to my main query. i.e select x.field1,y.field2 from tbl1 as x where x.field3 not in (select y.field3 from tbl2 as y) :confused:

            T Offline
            T Offline
            try88
            wrote on last edited by
            #5

            try this,may work. select x.field1,y.field2 from tbl1 as x,tbl2 as y where x.field3 != y.field3 青山隐隐水迢迢,秋尽江南草未凋。二十四桥明月夜,玉人何处教吹箫。

            B 1 Reply Last reply
            0
            • T try88

              try this,may work. select x.field1,y.field2 from tbl1 as x,tbl2 as y where x.field3 != y.field3 青山隐隐水迢迢,秋尽江南草未凋。二十四桥明月夜,玉人何处教吹箫。

              B Offline
              B Offline
              Ben Meyers
              wrote on last edited by
              #6

              The above will work, although you could also just do a normal inner join and use an inequality instead of the usual equality join, instead of the above example with a cartesian product and a where clause. SELECT x.field1, y.field2 FROM tbl1 as x INNER JOIN tbl2 as y ON x.field3 != y.field

              1 Reply Last reply
              0
              • M Michael Potter

                Sorry - didn't see your reference of y.field2 in the SELECT. Your original query will not work. You can try a left join:

                SELECT 
                    x.field1,
                    y.field2 
                FROM 
                    tbl1 x
                LEFT JOIN 
                    tbl2 y
                    ON (x.field3 = y.field3)
                WHERE 
                    y.field2 IS NULL
                

                -- modified at 14:37 Friday 10th February, 2006

                D Offline
                D Offline
                dev_rfid
                wrote on last edited by
                #7

                thanks, through it i solved my problem. thanks again.

                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