c_pattle Posted November 8, 2010 Share Posted November 8, 2010 I was wondering if it is possible to perform the following query. Say I have a list of names each with an id number ranging from 1 to 10. Is it possible to perform a query where you list all of these records while repeating one records. For example could I do a query that lists record number 6 then 10, 9, 8, 7, 6 etc. Or another example would be listing record number 10, then 10, 9, 8, 7, 6 etc? Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/218125-mysql-queries/ Share on other sites More sharing options...
sasa Posted November 8, 2010 Share Posted November 8, 2010 you can use UNION of two query. one for one record and 2nd for rest Quote Link to comment https://forums.phpfreaks.com/topic/218125-mysql-queries/#findComment-1131855 Share on other sites More sharing options...
OldWest Posted November 8, 2010 Share Posted November 8, 2010 I'm not sure I totally understand your question. Can you post some examples of the original data and expected output based on that data? Quote Link to comment https://forums.phpfreaks.com/topic/218125-mysql-queries/#findComment-1131935 Share on other sites More sharing options...
c_pattle Posted November 8, 2010 Author Share Posted November 8, 2010 Yeah sure. For example if there is a table called "names" with the following data. idname 1frank 2james 3harry 4casey Then I may want to do a query where I list all the records but repeating record number 3. Therefore the result would be, 3 - Harry 1. Frank 2. James 3. Harry 4. Casey Quote Link to comment https://forums.phpfreaks.com/topic/218125-mysql-queries/#findComment-1131955 Share on other sites More sharing options...
OldWest Posted November 8, 2010 Share Posted November 8, 2010 Do you mind telling me the basic reason (what use) you have in mind with repeating this data? Quote Link to comment https://forums.phpfreaks.com/topic/218125-mysql-queries/#findComment-1131958 Share on other sites More sharing options...
c_pattle Posted November 9, 2010 Author Share Posted November 9, 2010 I want to to do this because at the moment I am using two queries to create this results. It would be more efficient to use just 1 query so I was wondering if it can be done this way. Quote Link to comment https://forums.phpfreaks.com/topic/218125-mysql-queries/#findComment-1132329 Share on other sites More sharing options...
jdavidbakr Posted November 9, 2010 Share Posted November 9, 2010 I think sasa's answer is what you want - do a union of the two queries. Quote Link to comment https://forums.phpfreaks.com/topic/218125-mysql-queries/#findComment-1132408 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.