here im getting error when im using union all and order by newid() together, can any one help me to solve this issue..
select distinct * from(select top 500 (A.AdId),A.AdImgPath,A.OnAdURL,A.AdSize from KZ_AdDetails A,KZ_Add_Cat Cat,KZ_Add_City Cit where A.AddU_ID=Cat.AddU_ID and A.AddU_ID=Cit.AddU_ID and AdSize='250x250' order by newid()) X
union all
select distinct * from(select top 500 (A.AdId),A.AdImgPath,A.OnAdURL,A.AdSize from KZ_AdDetails A,KZ_Add_Cat Cat,KZ_Add_District Dis where A.AddU_ID=Cat.AddU_ID and A.AddU_ID=Dis.AddU_ID and AdSize='250x250' order by newid()) Y
regards
Divya
regards
Divya


Jignesh TrivediRank #16 · 50.3K reputationPosted May 30, 2013, 7:05 PM EDT
Query look ok, and also it work with newid() for my test data.
Can you please error desc?
Pankaj PandeyRank #642 · 3.7K reputationPosted May 30, 2013, 8:21 PM EDT
please share table scripts and error also.
divya146 reputationPosted May 31, 2013, 1:11 AM EDT
Thanku for u r response.Here im uploading tables ,please kindly find the attached file.Order by newid() is not working with union all...
Regards
Divya
Pankaj PandeyRank #642 · 3.7K reputationPosted May 31, 2013, 1:43 AM EDT
i have check it but in my machine its working well with data.
Pankaj PandeyRank #642 · 3.7K reputationPosted May 31, 2013, 1:43 AM EDT
i have check it but in my machine its working well with data.
may be this problem is with your data.
Jignesh TrivediRank #16 · 50.3K reputationPosted May 31, 2013, 2:02 AM EDT
hi,
with the test data it work fine for me.
Are you getting any error? or data mismatch?
divya146 reputationPosted May 31, 2013, 2:06 AM EDT
Thanku Pankaj Pandey sir,Have u verified that order by newid is working properly??????
Pankaj PandeyRank #642 · 3.7K reputationPosted May 31, 2013, 3:07 AM EDT
i have varified with insertion of some data manually.
it working....may be this problem is comming with live data..
id you can then do one thing...export data into csv format of all tables, and upload here, i will check it then may be i help you..
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 25, 2013, 11:26 PM EDT
Modify your query as like below
select distinct * from(
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.