SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Miami, Florida - Caracas, Venezuela
    Posts
    379
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multicolumn sorting with condition?

    Hi,

    I have a table with a column for regular price and a column for special price. I need to sort by the lowest price.

    If a particular record contains a special price sorting should use this price instead of the regular price.

    Basically I have to ignore the regular price if a special price is not 0.00.

    Can I do this in SQL [MySQL 4.012]?

    If so, how?

    Thank you,
    Luis

  2. #2
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is for SQL Server (off the top of my head though), so you may need to make slight changes for MySQL syntax:
    Code:
    SELECT .....
    FROM .....
    WHERE .....
    ORDER BY IIF([SPECIALPRICE]>0,[SPECIALPRICE],[NORMALPRICE])
    Last edited by M@rco; Jun 3, 2003 at 09:54.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

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