Results 1 to 5 of 5

Hybrid View

  1. #1

    MySQL query problem

    Any obvious reason this query does not work as expected? it returns the correct records - but ignores the Order By request:

    Code:
    select distinct sql_calc_found_rows b.*, u.username from sc_users as u, sc_bookmarks as b 
    where b.uid = u.uid and ((b.bstatus = 0) or (b.uid = 1)) and b.uid = 1 ORDER BY b.bDatetime desc
    This similar one does work correctly:

    Code:
    select distinct sql_calc_found_rows b.*, u.username from sc_users as u, sc_tags AS T0, sc_bookmarks as b 
    where b.uid = u.uid and ((b.bstatus = 0) or (b.uid = 1)) and b.uid = 1 AND T0.bid = b.bid ORDER BY b.bDatetime asc

  2. #2
    Join Date
    Mar 2006
    Posts
    984
    select distinct sql_calc_found_rows b.*, u.username from sc_users as u, sc_bookmarks as b
    where b.uid = u.uid and ((b.bstatus = 0) or (b.uid = 1)) and b.uid = 1 ORDER BY b.bDatetime desc
    for:

    Code:
    SELECT DISTINCT sql_calc_found_rows b.*, u.username
    FROM sc_bookmarks b
    LEFT JOIN sc_users u ON (u.uid = b.uid)
    WHERE ((b.bstatus = 0) OR (b.uid = 1)) AND b.uid = 1
    ORDER BY b.bDatetime DESC

  3. #3

    Not quite?

    I am not much of a SQL expert - do not have the hang of this obviously - as this is throwing an error:

    Code:
    SELECT DISTINCT sql_calc_found_rows b*, u.username
    FROM sc_bookmarks b
    LEFT JOIN sc_users u ON (u.uid = b.uid)
    WHERE ((b.bstatus = 0) OR (b.uid = 1)) AND b.uid = 1
    ORDER BY b.bDatetime DESC
    Code:
    #1064 - You have an error in your SQL syntax; check the manual that 
    corresponds to your MySQL server version for the right syntax to use near 
    ' u . username  FROM sc_bookmarks b  LEFT JOIN sc_users u ON ( u . uid = b . uid ' at line 1

  4. #4
    Join Date
    Mar 2006
    Posts
    984
    In my posted version, there was a dot in it:

    Code:
    b.*, u.username

  5. #5
    Well - absolutely right.

    I lost the "." somewhere - but when I was studying the code - it was in the forum - with the "." so I did not catch it.

    Gracias. Now - I just have to translate it back into the PHP to get it working.

Posting Permissions

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