...

View Full Version : alternate sort, order by



BubikolRamios
04-26-2009, 10:34 AM
Lets say I have a table with banners, some of them ar mine (marked as A) to point out my site contence, the others are comercial ones.

The data is added as web site goes on

data


flag
1.jpg A
2.jpg
3.jpg A
4.png A
5.png
6.png
7.png
.......
10.png A
11.png
12.png
.......

The A comes in randomly, 'not A' allso.

Would like to have a select that would return:


flag
1.jpg A
2.jpg
3.jpg A
5.png
4.png A
6.png
10.png A
7.png
11.png
12.png
.......


Everey second one mine. Doubt that this can done with sql ?

Old Pedant
04-26-2009, 11:24 PM
I guess you could do it with a Stored Procedure: You'd create a temporary table then use a pair of SELECTs and a cursor to put alternating rows into it.

Hmmm.... Maybe another way:

(1) Create two new tables, with autonumber first field (say it is "pid").
(2) Insert all the "A" records into first table.
(3) Insert all the non-A records into second table.
(4) Then execute this query:


SELECT pid, 1 AS subpid, imagename FROM first
UNION
SELECT pid, 2, imagename FROM second
ORDER BY pid, subpid


How's that?

BubikolRamios
04-27-2009, 12:50 PM
Excelent !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum