Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Mainataining Column Order in Recordset

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!
Before posting, make sure you have read this topic!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
   

T O P I C    R E V I E W
Shaggy Posted - 27 October 2011 : 11:35:38
OK, bare with me here, my brain's a bit mushy at the moment!

Say, for example, I have a table (ONE) with 5 records in it, each with a unique ID. In another table (TWO) I have some records, each with 5 columns. Using those 5 columns in TWO, I want to select the information from ONE ordering it by the order of the columns in TWO.

So my tables would be:
ONE
---
ID	FIELD
1	abc
2	def
3	ghi
4	jkl
5	mno

TWO
---
ID	COL1	COL2	COL3	COL4	COL5
1	3	1	2	5	4
And my query would be:
SELECT O.FIELD FROM ONE O,TWO T WHERE O.ID IN (T.COL1,T.COL2,T.COL3,T.COL4,T.COL5) AND T.ID=1
And I want the returned recordset to be in the order:
  • ghi
  • abc
  • def
  • mno
  • jkl
Any suggestions on how I'd achieve that without using any more tables or columns?

<edit>Figured it out - forgot I'd managed to achieve this before using MySQL's "FIELD" function. So now my query looks like this:
SELECT O.FIELD FROM ONE O,TWO T WHERE O.ID IN (T.COL1,T.COL2,T.COL3,T.COL4,T.COL5) AND T.ID=1 ORDER BY FIELD(O.ID,T.COL1,T.COL2,T.COL3,T.COL4,T.COL5)
And returns the recordset in the desired order. Huzzah! </edit>

2   L A T E S T    R E P L I E S    (Newest First)
Shaggy Posted - 27 October 2011 : 12:48:05
I say what I mean and I mean what I say!

Carefree Posted - 27 October 2011 : 11:58:08
LOL Shaggy, maybe your brain was a bit mushy. You meant "bear with me" vs "bare with me" (which means to denude or to strip). I don't think anyone taking their clothing off would have helped think through the process.

Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000 Version 3.4.07