Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Two query results mixed together


Two query results mixed together

Author
Message
k.vizay
k.vizay
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 52
Dear All,

I am facing a very strange problem and i would highly appreciate if some one can help me.

i have 3 query and their results inserting into a temp table but the results of one query gets clubbed with another query.

Ex. 1 Query . insert into temp select top 2 * from table (5 columns)
Query . insert into temp values('','','','','') [extra line break for visibility]

2 Query . insert into temp select top 2 * from table1 (5 columns)
Query . insert into temp values('','','','','') [extra line break for visibility]

3 Query . insert into temp select top 2 * from table (5 columns)

Now few reocrds of query 1 result gets merge with query 3 result.

I am in dilemma why exactly it happens as i had tried delay for five seconds between each query.

Please suggest me to sort out this issue.

Thanks in Advance.

Vizay
Ramesh Saive
Ramesh Saive
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2564 Visits: 2643
I don't think I understood very well, can explain us what do you mean by "the results of one query gets clubbed with another query"? How about adding some sample data with the generated output for the sample data?

--Ramesh


k.vizay
k.vizay
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 52
Hi ,

It means that when i select the list from temp table i found that few records of 1 query get display with the records of 3 query.

Ex . if 1 query returns 50 rows and and 3 query returns 20 rows then ... while reviewing the result set from temp table ... i see 45 records from 1 query and 25 records from 3 query.

As i have put some spaces between the queries so that it can be easily understood the result set of all 3 different queries...

I hope this time i had explained properly...

Regards,
Vizay
Ramesh Saive
Ramesh Saive
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2564 Visits: 2643
If you want the rows from a query to be returned in any specific order then you must specify the ORDER BY clause. For e.g.

SELECT * FROM SomeTempTable ORDER BY SomeKey

--Ramesh


David Lester
David Lester
SSC-Enthusiastic
SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)SSC-Enthusiastic (187 reputation)

Group: General Forum Members
Points: 187 Visits: 1542
Are you trying to get 3 different result sets with the queries?
Or
One table with the results from 3 different queries in it?
Naked Ape
Naked Ape
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 703
You could add a "sort" column to your temporary table - like an Identity column that simply generates a sequential number, incremented for each row inserted into the table.

You can then use ORDER BY when querying from the temp table, which should give you the result you are after.

Chris
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search