Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts

    alternate sort, order by

    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
    Code:
                     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:
    Code:
                     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 ?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,869
    Thanks
    79
    Thanked 4,418 Times in 4,383 Posts
    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:
    Code:
    SELECT pid, 1 AS subpid, imagename FROM first
    UNION 
    SELECT pid, 2, imagename FROM second
    ORDER BY pid, subpid
    How's that?

  • Users who have thanked Old Pedant for this post:

    BubikolRamios (04-27-2009)

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    Excelent !


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •