Hi all,

I have the following query i'm running through a PHP script:

SELECT DISTINCT board_threads.*
FROM board_threads
LEFT JOIN  board_replies
ON board_threads.id = board_replies.threadid
WHERE (board_threads.stamp > '{$startDate}' OR board_replies.stamp >
'{$startDate}')
ORDER BY board_threads.id DESC


Quick translation:  Show threads on a msg board, only if:
a) the thread was created in the last 7 days
b) the thread has replies within the last 7 days

The stamp field in both tables is a unix time stamp.


It works as expected, and I'm happy, however, I'd liek to know a few things
(to help me learn):

1. Is there anyway this can be optimised?


2. Why was I getting SOME threads returned twice when I didn't have
"DISTINCT" in there?


3. Currently, the results are ordered by board_threads.id... is it possible
to order them by date?   The issue is that there are multiple dates to
consider...

- board_threads.stamp
  (the timestamp the thread was created)
- board_replies.stamp
  (the timestamp each reply was created -- there may be zero or more
replies, so the newest stamp of these should be taken)


Any help appreciated, or links to a magical page that enables me to find out
for myself :)


Thanks,

Justin French
--------------------
http://Indent.com.au
Web Developent & 
Graphic Design
--------------------


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to