Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy do aliases cause my query to fail in phpMyAdmin?
    primarykey
    data
    text
    <p>The following query works fine in my php script, but when I run it in phpMyAdmin (against the same database), I get no results (not even "0 results" -- it just refreshes the page). </p> <pre><code> SELECT comment, username, image, post_date, ((us.user_id != 22) AND ((SELECT read_date FROM bookmarks WHERE product_id=456029 AND user_id=22) &lt; post_date)) AS new_comment FROM comments AS co, users AS us, flair WHERE co.product_id=456029 AND co.user_id=us.user_id AND flair_id=us.active_flair_id ORDER BY co.post_date ASC </code></pre> <p>I noticed that if I take out the aliases, the query works in phpMyAdmin</p> <pre><code>SELECT comment, username, image, post_date, ((users.user_id != 22) AND ((SELECT read_date FROM bookmarks WHERE product_id=456029 AND user_id=22) &lt; post_date)) AS new_comment FROM comments, users, flair WHERE comments.product_id=456029 AND comments.user_id=users.user_id AND flair_id=users.active_flair_id ORDER BY comments.post_date ASC </code></pre> <p>I am curious why this would happen. (running phpMyAdmin - 2.11.9.5)</p> <p>EDIT: Richard's reformulation below works in phpMyAdmin. So now the puzzle is why one formulation works and the other doesn't (when they both work fine when executed in a php script).</p> <p>the final form of the query following Richard's advice to remove the subquery:</p> <pre><code>SELECT c.comment AS COMMENT , username, image, DATE_FORMAT( c.post_date, '%b %D, %Y' ) AS post_date, IF( ( ( b.read_date IS NULL ) OR ( b.read_date &lt; c.post_date ) ) , IF( c.user_id !=1, 1, 0 ) , 0 ) AS new_comment FROM comments c INNER JOIN users u ON c.user_id = u.user_id INNER JOIN flair f ON flair_id = u.active_flair_id LEFT JOIN bookmarks b ON ( b.product_id = c.product_id AND b.user_id =1 ) WHERE c.product_id =538968 ORDER BY c.post_date ASC </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload