Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Which idea is better returning more than one result set or perform a join

Posted on 2008-10-07
6
Medium Priority
?
185 Views
Last Modified: 2010-03-19
Which approach is better?

Returning Multiple Result sets:
SELECT [CAR_LOAD_ID]
      ,[CAR_ORDER_FL]
      ,[CAR_WELL_ID]
      ,[POSITION_NR]
      ,[EQUIP_AN]
      ,[COMMENT_DS]
  FROM [CAR_LOAD_T]
where CAR_ID = 2


select      [TRAIN_LOAD_ID]
      ,[TRAIN_ID]
      ,[TRAIN_TRACK_ID]
      ,[POSITION_ID]
      ,[DEST_TRAIN_CODE_ID]
      ,[LOAD_DT]
      ,[LOAD_BY_AN]
      ,[CAR_TRACK_ID]
      ,[WELL_ORDER_FL]
from [TRAIN_LOAD_T] tl
where CAR_ID = 2

select [CAR_LENGTH_NR]
from CARS_T
where CAR_ID = 2


or perform a join:

SELECT cl.[CAR_LOAD_ID]
      ,cl.[CAR_ORDER_FL]
      ,cl.[CAR_WELL_ID]
      ,cl.[POSITION_NR]
      ,cl.[EQUIP_AN]
      ,cl.[COMMENT_DS]
      ,tl.[TRAIN_LOAD_ID]
      ,tl.[TRAIN_ID]
      ,tl.[TRAIN_TRACK_ID]
      ,tl.[POSITION_ID]
      ,tl.[DEST_TRAIN_CODE_ID]
      ,tl.[LOAD_DT]
      ,tl.[LOAD_BY_AN]
      ,tl.[CAR_TRACK_ID]
      ,tl.[WELL_ORDER_FL]
,c.[CAR_LENGTH_NR]
  FROM [CAR_LOAD_T] cl
  join [TRAIN_LOAD_T] tl
on tl.[CAR_ID] = cl.[CAR_ID]
join CARS_T c
on c.CAR_ID = tl.CAR_ID
where c.CAR_ID = 2

I am using both in my app and i like the multiple result set approach. WAY less C# code to type cause a join returns the same data over and over and i have to check for different values.
0
Comment
Question by:troycomp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 22665063
It really depends.  If youre using the result sets separately, thene get them separately.  If you're using them together (a tran_id and a car_well_id at the same time) then join them.  Remember, don't pull back fields in the SELECT statement unless you absolutely need them.
0
 

Author Comment

by:troycomp
ID: 22665084
Im using them together. Whats so "bad" about the multiple result sets? If anything. A join returns more data than multiple result sets cause if a value is found once in table a but table b its found 10 times, you'll get table a results 10 times as well
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 22665097
>>Whats so "bad" about the multiple result sets?
Nothing, really.  It all depends on how you want it.  If you're not going to need them combined, then don't combine them.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:troycomp
ID: 22665113
Im working on a big project and its due at the end of this month. Im trying to write as little C# code as possible, but i want to make it as efficient as possible. So if im not gonna take a performance hit for not joining then i'm gonna use result sets. Will i take a performance hit for this?
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 750 total points
ID: 22665159
Without knowing what you're dong in your app, there is no way I can tell you if your performance is going to be better or worse by choosing two queries or one.
0
 

Author Comment

by:troycomp
ID: 22665171
Thanks for your input
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question