473,769 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need More SQL Query NewID Help

Excuse my ignorance because I don't do advance db related programming,
but have no other choice at the moment. My experience is limited to
simple queries.

I need to have the following query display the recordset in random order
based on RecordID (unique key) if possible. I tried the ORDER BY NewID()
at the end and it generated an error (ORDER BY items must appear in the
select list if SELECT DISTINCT is specified.) I guess because of the sub
query. I would also like for the recordset to display a different 10
records on each hit to the page, not just the same 10 records in random
order. I wasn't sure if the SELECT commands I have in place are
sufficient for this task.

Thanks in advance for any assistance.

SELECT DISTINCT
TOP 10 dbo.ShowcaseRid es.RecordID,
dbo.ShowcaseRid es.CustomerID, dbo.ShowcaseRid es.PhotoLibID,
dbo.ShowcaseRid es.Year,
dbo.ShowcaseRid es.MakeShowcase ,
dbo.ShowcaseRid es.ModelShowcas e, dbo.ShowcaseRid es.VehicleTitle ,
dbo.ShowcaseRid es.NickName,
dbo.ShowcaseRid es.SiteURL,
dbo.ShowcaseRid es.ShowcaseRati ng, dbo.ShowcaseRid es.ShowcaseRati ngImage,
dbo.ShowcaseRid es.ReviewDate,
dbo.ShowcaseRid es.Home,
dbo.ShowcaseRid es.EntryDate, dbo.Customers.U serName,
dbo.Customers.S hipCity, dbo.Customers.S hipRegion,
dbo.Customers.S hipPostalCode,
dbo.Customers.S hipCountry, dbo.Customers.L astName,
dbo.Customers.F irstName, dbo.Customers.M emberSince,
dbo.ShowcaseRid es.Live,
dbo.ShowcaseRid es.MemberLive, dbo.Accessories .Make,
dbo.Accessories .Model, Photos.Path
FROM dbo.ShowcaseRid es INNER JOIN
dbo.Customers ON dbo.ShowcaseRid es.CustomerID =
dbo.Customers.C ustomerID INNER JOIN
dbo.Accessories ON dbo.ShowcaseRid es.MakeShowcase
= dbo.Accessories .MakeShowcase AND
dbo.ShowcaseRid es.ModelShowcas e =
dbo.Accessories .ModelShowcase INNER JOIN
(SELECT MIN(dbo.Showcas ePhotos.PhotoPa th)
AS Path, RecordID
FROM dbo.ShowcasePho tos
GROUP BY RecordID) Photos ON
dbo.ShowcaseRid es.RecordID = Photos.RecordID INNER JOIN
dbo.ShowcasePho tos ON Photos.Path =
dbo.ShowcasePho tos.PhotoPath
WHERE (dbo.ShowcaseRi des.MemberLive = 1) AND (dbo.ShowcaseRi des.Live
= 1) AND (dbo.ShowcaseRi des.MakeShowcas e = @MMColParam)
ORDER BY dbo.ShowcaseRid es.EntryDate DESC

Regards,

Darin L. Miller
Paradyse Development
~-~-~-~-~-~-~-~-~-~-~-~-~-~-
"Some things are true whether you believe them or not." - Nicolas Cage
in City of Angels
Jul 7 '06 #1
3 2185
Paradyse (su*****@parady sed.com) writes:
Excuse my ignorance because I don't do advance db related programming,
but have no other choice at the moment. My experience is limited to
simple queries.

I need to have the following query display the recordset in random order
based on RecordID (unique key) if possible. I tried the ORDER BY NewID()
at the end and it generated an error (ORDER BY items must appear in the
select list if SELECT DISTINCT is specified.) I guess because of the sub
query. I would also like for the recordset to display a different 10
records on each hit to the page, not just the same 10 records in random
order. I wasn't sure if the SELECT commands I have in place are
sufficient for this task.
Hugo has already asked why you have the DISTINCT there. Have you tried
simply to remove it?
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 7 '06 #2
I removed the DISTINCT and it showed the same record 10 times. Who is
Hugo?

"Erland Sommarskog" <es****@sommars kog.sewrote in message
news:Xn******** *************@1 27.0.0.1:
Paradyse (su*****@parady sed.com) writes:
Excuse my ignorance because I don't do advance db related programming,
but have no other choice at the moment. My experience is limited to
simple queries.

I need to have the following query display the recordset in random order
based on RecordID (unique key) if possible. I tried the ORDER BY NewID()
at the end and it generated an error (ORDER BY items must appear in the
select list if SELECT DISTINCT is specified.) I guess because of the sub
query. I would also like for the recordset to display a different 10
records on each hit to the page, not just the same 10 records in random
order. I wasn't sure if the SELECT commands I have in place are
sufficient for this task.

Hugo has already asked why you have the DISTINCT there. Have you tried
simply to remove it?
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 8 '06 #3
Paradyse (su*****@parady sed.com) writes:
I removed the DISTINCT and it showed the same record 10 times.
Looks like you have to refine the query to weed out the duplicates then.
Probably you have an in sufficient join condition somewhere.

Without knowledge of the tables, and how they are related, it's difficult
to assist. At a very minimum we would need to see the table definition
including keys. You can script table definitions from Enterprise Manager
or SQL Server Managerment Studio, whichever you are using. Make us a
favour and remove [] and COLLATE clauses before you post it.

You could also try to cut down the query and removing tables until you
no longer get the duplicates. The point would be to track down how the
duplicates are introduced, and then you can work from there.
Who is Hugo?
Hugo is Hugo Kornelis, another SQL Server MVP. I'm fairly sure that he
responded to one of your earlier posts.


--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1663
by: Tony | last post by:
Thanks for writing back and don't laugh at what I am about to post I am new to this type of stuff....this is what I have tried and it isn't working(please note in the try section I was just trying to see if it was grabbing my variable or not any suggestions or hints would be greatly appreciated: ******** Private Sub AddArticle()
2
1657
by: yvan | last post by:
I was wondering if someone here could help me with modifying this PHP template so that it does something very specific for me. My knowledge of PHP is very limited (I'm more of a Cold Fusion developer), which is why I'm inquiring here. Anyways, first I'll show you the PHP code, and then I'll explain what kind of modification I need to have applied: ------------------------------------------------------------------------------ <?
3
1149
by: Cem Louis | last post by:
Hi, I want to send to SQL server a query I want to get randomly generated 100 rows where they are no generated before. I made my query like below: mySqlCommand.CommandText = "SELECT name,rand(name) FROM people LIMIT 100 WHERE generated_before IS NULL"; Gives system error???
2
1755
by: mr.Hyde | last post by:
Hi, I am working with mscrm database. the Accounts has UniqueIdentifierID, so I am trying to use as parameter value in sqlcommand "NewId();", it doesnt works becouse, ExecuteNonQuery pass my parameter as "NewId();" - with quotas. How I can remove quotas from this command? Regards Hyde
2
17653
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
How can I run this query against a table in my Access database? I don't know hwo to use it in C#. In VB I would use .Recordset = "some sql statement". How do I do this in C#? //I get a vlaue form a cell and apply it to the SQL statement commandCol = scriptDataGridView.FormattedValue.ToString(); string sCommand = "SELECT CommandString FROM Commands WHERE CommandName = " + commandCol; //This reutne a valie SQL statement which will return...
0
6888
by: weird0 | last post by:
Here is the code for executing stored procedure ExecuteSP() , and object that sets all its parameters in other functions and the stored procedure. I think it has something to do with db datatypes since this is the first time, i am working with databases and not really much of an expert. How can I rectify it? One thing more...... Should I be passing a value to type bit in sql server as 0 or '0'..... '0' is for character i guess ...
13
5799
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table CatalogImage where imgID also needs to be placed. Below is my code behind to carry the catID using the Select @@Identity and insert imgID to the bridge table. No data is being entered into the bridge table.
2
2474
by: huiling25 | last post by:
I was given the pseudo code.. but i still cannot figure out how to do it... how can i find if the vertices are adjacent to the vertex on stack top? I know i have to have an array of true/false (to dictate if the vertex is being visited)... dfs(v) { create a stack s to store visited notes s.push(v) while(!s.isEmpty()) { if(no unvisited vertices are adjacent to the vertex on stack top) { //need a...
1
5107
sujathaeeshan
by: sujathaeeshan | last post by:
Hi all, Newid() which creates a unique value of type uniqueidentifier. Is there any possibolities for seeding or incrementing the NEWID() value. For example: create table cust(cust_id uniqueidentifier NOT NULL DEFAULT newid(),cust_name varchar(60) NOT NULL)
0
10212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.