|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, June 13, 2010 1:06 AM
Points: 2,
Visits: 4
|
|
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?
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, June 17, 2013 1:45 PM
Points: 15,442,
Visits: 9,572
|
|
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
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, June 13, 2010 1:06 AM
Points: 2,
Visits: 4
|
|
thanks for ur reply, but this scenario, i need to use with ASP.NET applications in a single sql statement
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, June 13, 2013 1:48 PM
Points: 1,084,
Visits: 811
|
|
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.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, June 17, 2013 1:45 PM
Points: 15,442,
Visits: 9,572
|
|
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
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Yesterday @ 11:54 PM
Points: 33,113,
Visits: 27,041
|
|
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."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|