SQL JOINS

  • Hi,

    I have a question when I went for an interview.

    let us say I have more than 5 tables and must join all the tables to get the required information.

    but the interviewer asked me how can we get the same data what I am getting by joining all these tables with out using SQL JOINS or UNION command.

    Q:Is there any other ways to get the data?

  • You could insert the data from the first table into a temp table that has all the columns you want to end up with, then use update commands to pull in the data from the other tables one table at a time.

    It's a dumb idea, but it does work.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • thanks for ur reply,

    but this scenario, i need to use with ASP.NET applications in a single sql statement

  • select a.column1, b.column1 from table1 a,table2 b where a.column2 = b.column4

    technically, it's a join, but doesn't use the join keyword. This style of join is going to be deprecated, so it is not recommended to use it.

  • You could use correlated inline queries.

    select Col1,

    (select ColA

    from dbo.Table2

    where ColB = Table1.Col2) as ColA

    from dbo.Table1;

    This is even worse than the temp table solution, but it does fit the requirements given thus far.

    I have to say, if anyone asked me this in an interview, I'd challenge it. "Why not use Join operations?" would be my response. Probably they just like trick questions to see if you can "think outside the box", but there are much better ways to accomplish that than asking you to avoid using a standard tool of the trade.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • I'm always fascinated by interviewers that think something needs to be done in a single SQL statement and I'm just as fascinated by interviewers that think you should generate such code from the application. So far as I'm concerned, the correct answer should be...

    EXEC dbname.schemaname.storeprocedurename(list of parameters)

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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