SQL JOINS

  • Raghavendra Mudugal

    SSChampion

    Points: 10658

    Koen Verbeeck (1/8/2013)


    Not sure what this question tries to teach us....

    I guess.. this; if the aliases are been removed in SELECT block, it gives below error on ambiguity for couple of column names. (some sort.... author might had in mind)

    Msg 209, Level 16, State 1, Line 3

    Ambiguous column name 'Name2'.

    Msg 209, Level 16, State 1, Line 4

    Ambiguous column name 'Name3'.

    (looks like this was one of the "out of the box" experience πŸ™‚ )

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.

  • Dana Medley

    SSCertifiable

    Points: 6764

    Koen Verbeeck (1/8/2013)


    Not sure what this question tries to teach us.

    I spend 5 minutes looking for a mistake, only to finally decide there wasn't one, all joins seemed legit. I got it right, but I suddenly was surprised the question was about table aliases.

    I'm with Koen on this one. I spent a few minutes (I think more than 5) analyzing the queries and looking for that "gotcha" that sticks out once you find it, but no such luck on that.



    Everything is awesome!

  • Keld Laursen (SEGES)

    SSC Eights!

    Points: 843

    I concur with many here. It were somewhat of a disappointment to end up with some alias-stuff after spending quite some time looking for the column not being aggregated, or, as I thought first, some union with disparaging column definitions or some such. But no, just straight aliasing.

    I am quite used to aliasing a lot of tables, and also making sure to get the right columns from the right tables when the names clashes, sΓ₯ the alias stuff were the last thing on my mind.

    But thank you for the question anyway. A good friday question, even on a wednesday πŸ™‚

    /Keld

  • mtassin

    SSC-Insane

    Points: 23099

    Koen Verbeeck (1/8/2013)


    Not sure what this question tries to teach us.

    I spend 5 minutes looking for a mistake, only to finally decide there wasn't one, all joins seemed legit. I got it right, but I suddenly was surprised the question was about table aliases.

    Same here... and since we went to wide short monitors I had to keep scrolling up and down to make sure I could keep the entire schema in my head.

    Koen Verbeeck (1/8/2013)


    Maybe I was more surprised that apparently the criteria for a query to run succesfully is to get your table aliases correct πŸ™‚

    Among other things πŸ™‚



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

  • Revenant

    SSC-Forever

    Points: 42467

    Thanks for an easy question.

    However, I noticed then if the QotD offers choice 'this will run' and 'this will not run', in most cases the answer is 'it will', so the question is reduced to 'is there an egregious problem?'. Which takes a good deal of fun out of figuring out the correct answer.

  • chgn01

    Hall of Fame

    Points: 3684

    Thanks for all comments. we use aliases in joins. Aliases are not for columns where there is only one column possible. But it is nice to have all aliases listed just for maintainability in joins.

    --------------------------------------
    ;-)β€œEverything has beauty, but not everyone sees it.” ― Confucius

  • SQLRNNR

    SSC Guru

    Points: 281243

    sqlnaive (1/9/2013)


    Dineshbabu (1/8/2013)


    Andre Ranieri (1/8/2013)


    Nice question - I wonder if the question category should have been table aliases instead of joins πŸ™‚

    Thanks,

    Andre Ranieri

    +1

    I agree with both Andre and Dineshbabu. Was looking for any issues in the joins for couple of minutes but found no issues.

    +1

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Toreador

    SSChampion

    Points: 11256

    chgn01 (1/9/2013)


    Aliases are not for columns where there is only one column possible.

    Whyever not?

  • OCTom

    SSChampion

    Points: 11755

    chgn01 (1/9/2013)


    Thanks for all comments. we use aliases in joins. Aliases are not for columns where there is only one column possible. But it is nice to have all aliases listed just for maintainability in joins.

    For my learning... how does using aliases affect maintainability?

    Thanks,

    Tom

  • Miles Neale

    SSChampion

    Points: 13147

    Nice, had to think about it far a few minutes but got it.

    Thanks

    Not all gray hairs are Dinosaurs!

  • Rob Schripsema

    SSCertifiable

    Points: 7469

    Revenant (1/9/2013)


    Thanks for an easy question.

    However, I noticed then if the QotD offers choice 'this will run' and 'this will not run', in most cases the answer is 'it will', so the question is reduced to 'is there an egregious problem?'. Which takes a good deal of fun out of figuring out the correct answer.

    Agreed.

    Rob Schripsema
    Propack, Inc.

  • jvac

    SSC Journeyman

    Points: 94

    Good question, got it! Thanks

    _______________________________________________________________
    "The best way to prepare for programming is to write programs, and
    to study great programs that other people have written." – Bill Gates

  • Ken Wymore

    SSCoach

    Points: 16592

    Thanks for the easy question. Glad I didn't second guess myself.

  • PChiragS

    SSCarpal Tunnel

    Points: 4965

    Easy one.. but good question..

    Thanks..

  • kalyani.k478

    Default port

    Points: 1400

    +1

Viewing 15 posts - 16 through 30 (of 34 total)

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