Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SQL JOINS Expand / Collapse
Author
Message
Posted Friday, September 11, 2009 12:25 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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?
Post #786635
Posted Friday, September 11, 2009 12:38 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Monday, April 14, 2014 1:34 PM
Points: 15,442, Visits: 9,588
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
Post #786641
Posted Friday, September 11, 2009 12:49 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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
Post #786649
Posted Friday, September 11, 2009 12:55 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, April 17, 2014 3:20 PM
Points: 1,128, Visits: 925
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.
Post #786655
Posted Friday, September 11, 2009 1:26 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Monday, April 14, 2014 1:34 PM
Points: 15,442, Visits: 9,588
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
Post #786673
Posted Friday, September 11, 2009 9:18 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 4:00 PM
Points: 35,967, Visits: 30,258
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." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #786796
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse