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. JOIN and WHERE condiiton

JOIN and WHERE condiiton

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

    hi, suppose i have 2 tables table1,table2 i wrote the following join query

    SELECT * FROM table1 AS T1
    JOIN table2 AS T2 ON T1.idtable1 = T2.idtable1
    WHERE T1.idtable1 > 10

    My Question: Is the WHERE condition applies in the JOINED result ? Or the where is used before JOINing?

    My small attempt...

    B P W 3 Replies Last reply
    0
    • S sujithkumarsl

      hi, suppose i have 2 tables table1,table2 i wrote the following join query

      SELECT * FROM table1 AS T1
      JOIN table2 AS T2 ON T1.idtable1 = T2.idtable1
      WHERE T1.idtable1 > 10

      My Question: Is the WHERE condition applies in the JOINED result ? Or the where is used before JOINing?

      My small attempt...

      B Offline
      B Offline
      Blikkies
      wrote on last edited by
      #2

      It does apply in the JOINED result

      1 Reply Last reply
      0
      • S sujithkumarsl

        hi, suppose i have 2 tables table1,table2 i wrote the following join query

        SELECT * FROM table1 AS T1
        JOIN table2 AS T2 ON T1.idtable1 = T2.idtable1
        WHERE T1.idtable1 > 10

        My Question: Is the WHERE condition applies in the JOINED result ? Or the where is used before JOINing?

        My small attempt...

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

        It is applied to the result of the join. In the past I have tried to "optimize" such statements as:

        SELECT * FROM table1 AS T1
        JOIN table2 AS T2
        ON T1.idtable1 > 10
        AND T1.idtable1 = T2.idtable1

        but saw no improvement.

        1 Reply Last reply
        0
        • S sujithkumarsl

          hi, suppose i have 2 tables table1,table2 i wrote the following join query

          SELECT * FROM table1 AS T1
          JOIN table2 AS T2 ON T1.idtable1 = T2.idtable1
          WHERE T1.idtable1 > 10

          My Question: Is the WHERE condition applies in the JOINED result ? Or the where is used before JOINing?

          My small attempt...

          W Offline
          W Offline
          WoutL
          wrote on last edited by
          #4

          I think that depends on the database you are using. MS SQL would apply the where clause before the join. And you caan check this by getting the query-plan.

          Wout Louwers

          E 1 Reply Last reply
          0
          • W WoutL

            I think that depends on the database you are using. MS SQL would apply the where clause before the join. And you caan check this by getting the query-plan.

            Wout Louwers

            E Offline
            E Offline
            ElectricLlama
            wrote on last edited by
            #5

            AFAIK SQL Server applies it before or after the join depending on what it thinks would give you the quickest result.

            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