Welcome, Guest
  • Author Topic: Tricky query..  (Read 4069 times)

    Mattias Robo

    • Mods
    • Systems Administrator
    • *****
    • Posts: 555
      • View Profile
      • nook
    Tricky query..
    « on: 12/06/07, 19:19 »
    I'm not sure if this is possible at all but here it goes..

    table
    ID | Name

    What I'd like to do is to pick all rows and sort them by 'Name', BUT I'd like the 'Name' field of some rows to be stored under a different variable (Like in 'SELECT Name as somethingelse').


    Example:

    table
    1 | "foo"
    2 | "bar"

    sql: SELECT Name (where ID=1) and Name as Name2 (where ID=2) ORDER BY Name

    result: [Name2 ("bar"), Name ("foo")]


    The reason is that I have a lot of rows where I want to pick names in order but being able to differentiate them depending to another field.
         "I've figured it out. It's not the fords... it's what's IN them!.."

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: Tricky query..
    « Reply #1 on: 12/07/07, 03:14 »
    this sounds weird and quite unstructured ;)

    If you make more clear what you realy are trying to do, we possibly can find a solution.
    happy flashing
    8)
    Ronald

    Mattias Robo

    • Mods
    • Systems Administrator
    • *****
    • Posts: 555
      • View Profile
      • nook
    Re: Tricky query..
    « Reply #2 on: 12/07/07, 13:59 »
    Heh.. ok I'll try to give you an idea. I mean I can think of a lot of different solutions but it just would be very smooth if I could do it this way.

    Imagine this table:

    persons
    ID | Firstname | Age | Height

    On a webpage you list Name, Age and Height in three columns with distinct values (if two persons have the same age you only list that age once etc).
    Now, if you click an age you want to mark what persons have that age and what heights is represented by the same persons. If you then click a height, the persons with the chosen age and height sould be marked.
    By "marked" I mean that you still want to list all persons but the "marked" ones should be visually different.
    This is why I'd like to retrieve all names but some of them as a different fieldName to be able to treat them differently. I also need to use SQL to figure out what entries should be "marked" depending on choices.

    Still not making any sense?  :-\
    « Last Edit: 12/07/07, 14:01 by Mattias Robo »
         "I've figured it out. It's not the fords... it's what's IN them!.."

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re: Tricky query..
    « Reply #3 on: 12/07/07, 14:13 »
    Hm - not realy something for SQL only - you can handle it with a script.
    Depending on the amount of data, it could make sense to do this inside of the presentation level (if frontend is flash, do it in AS-Script, else in Javascript).
    Or make a roundtrip through php.
    happy flashing
    8)
    Ronald

    Mattias Robo

    • Mods
    • Systems Administrator
    • *****
    • Posts: 555
      • View Profile
      • nook
    Re: Tricky query..
    « Reply #4 on: 12/07/07, 20:31 »
    Yes I guess that's what I have to do.

    I have just started working with SQL and have realised it has great potential and just wanted to see if it could be solved using it. But this one was apperantly a bit over the top.

    Thanks for your comments!
         "I've figured it out. It's not the fords... it's what's IN them!.."