Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009

    Unanswered: Order By question

    I have this query which has a conflict when I try to add a ORDER BY. The "colname(1-7)" are variables passed by the URL.
    My goal is to have the results sorted by date (cdate_img) which is a common field in image_img and Exhibit

    The page can be viewed at: Untitled Document

    SELECT filename_img, id_img
    FROM image_img
    LEFT JOIN label ON id_lbl=(theme_img
    OR style_img
    OR medium_img
    OR season_img)
    LEFT JOIN artist_art
    On artist_img=user_art
    WHERE approvedIMG=1
    AND (private_img <>1
    OR `private_img`IS NULL )
    AND (medium_img Like colname3
    OR artist_img=colname
    OR season_img LIKE colname2
    OR theme_img LIKE colname4
    OR style_img LIKE colname5
    OR country_art LIKE colname6
    OR 'ALL'=colname8)
    SELECT filename_img, id_img_eximg AS id_img
    FROM Exhibit
    LEFT JOIN ExhibitImages ON Exhibit.id_ex=ExhibitImages.exhibit_eximg
    LEFT JOIN image_img ON id_img_eximg=id_img
    WHERE id_ex=colname7

    I realize there are several ways of building this query, perhaps using case or subquerys

    I appreciate any help,


  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    in a UNION query, if you want to sort the results, you must include the sort column in the SELECT clauses

    you have a syntax error in the first SELECT --
    ON id_lbl=(theme_img OR style_img OR medium_img OR season_img)
    also, your query is extremely difficult to understand because you did not qualify any of the column names!! | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2009


    Thanks Rudy, I'll study this and get back to you.


Posting Permissions

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