![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| Hi everybody, I have a little problem selecting random records from a MySQL database. At the moment, my query looks like: --- query --- select seq, artist, credat, upddat from artists order by rand() limit 10 --- /query --- which selects a maximum of 10 random records from the database. The problem is that I would like to have these records sorted by artist. Coming from an Oracle background, I'd write it as follows: --- query --- select seq, artist, credat, upddat from ( (insert original select) ) order by artist --- /query --- but apparently this does not work. The error I receive is "1248: every derived table must have its own alias". What is the best/easiest way to solve this? As an emergency solution, I can sort the details outside of the database in my program, but that is not a good practice. Thanks in advance, Ikke | |||
| Advertisements |
| | #2 | ||
| Ikke wrote: > Hi everybody, > > I have a little problem selecting random records from a MySQL > database. > > At the moment, my query looks like: > --- query --- > select seq, artist, credat, upddat from artists > order by rand() limit 10 > --- /query --- > which selects a maximum of 10 random records from the database. > > The problem is that I would like to have these records sorted by > artist. Coming from an Oracle background, I'd write it as follows: > --- query --- > select seq, artist, credat, upddat from > ( > (insert original select) > ) > order by artist > --- /query --- > but apparently this does not work. The error I receive is "1248: every > derived table must have its own alias". Hmmz, I thought that would work. If they say you need an alias, why not give it: select z.seq, z.artist, z.credat, z.upddat from ( (insert original select) ) as z order by artist -- Rik Wasmus | |||
| | #3 | ||
| "Rik" <luiheidsgoeroe@hotmail.com> wrote in news:5eabf$4549dd97$8259c69c $23695@news2.tudelft.nl: <snip> > Hmmz, I thought that would work. > If they say you need an alias, why not give it: > select z.seq, z.artist, z.credat, z.upddat from > ( > (insert original select) > ) as z > order by artist Thanks - I was trying to add the alias to the original select, which of course failed miserably. Now I get it Best regards, Ikke | |||
| Featured Websites | ||||
|
![]() |
| Tags: problem, random, records, selecting |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| selecting by date | Peter | Database | 1 | 05-31-2007 8:47 PM |
| Export MS Access tables with random autonumber fields to MySQL | GGL | Database | 0 | 05-31-2007 8:39 PM |
| random number generator | Kadaitcha Man | Windows | 6 | 05-28-2007 8:45 PM |
| Random Things Discussion | mayank | Community Chat | 45 | 04-02-2006 11:29 AM |
| Featured Websites | ||||
|