Bad Join syntax?

  • I came across some bad code at a new job and was wondering why this works or compiles?

    SELECT

    a.*

    FROM table1 as a INNER JOIN table2 as b

    ON a.somecolumn <= b.somecolumn
    Isn't the less than pointless?

  • >>Isn't the less than pointless?

    Why would it be pointless ? It depends on the functionality required. What if table2 represents some point in time, and you're trying to return all events from table 1 that occurred on or before that date ?

     

  • Unequal and exotic joins are one of the most powerfull feature of tsql. You can find 5K exemples of their use on this site alone.

  • Seems a little bizare to me because if for a row in table1, there are 10 rows in Table2 where th join criteria is true, then there will be 10 identical rows in the result.  This does not seem correct.

    More appropriate might be:

    SELECT table1.*

    FROM table1

    WHERE EXISTS

    (select 1 from table2

    where table1.somecolumn <= table2.somecolumn)

    SQL = Scarcely Qualifies as a Language

  • I agree with Carl as it seems there would be identical rows in the resultset which doesn't make any sense to me.

  • >>I agree with Carl as it seems there would be identical rows in the resultset which doesn't make any sense to me.

    No-one in the forum really knows, do they ? Without table DDL's, we don't know what the query is doing and on what columns & datatypes.

    How can *we* know it produces identical rows in the resultset, if we don't have a clue what table1 and table2 contain ? Therefore how can we judge it to be a "bad join" ?

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply