* P.Agenbag
<snip>
> So, how would the query string look that would only return ONE set of
> data for that specific property?

Use the LIMIT clause of the SELECT statement:

<URL: http://www.mysql.com/doc/S/E/SELECT.html >

In short: add "LIMIT 1" at the end of your query, and it will only return
one row.

> A possible solution from a different source suggest the following, but
> I'm not sure it will work as it looks to me as if it still returns more
> than one row(possibly).
>
> $sql = "select * from table where prop_name='$prop_name' and
> prop_type='$prop_type' and status='success' and
> action_date>('".date("Y-m-d")."',INTERVAL 12 MONTH group by ID order by
> action_date desc)";

This does not look right in my eyes... this statement may return multiple
rows, but only one row per 'ID', whatever that is... if it had been GROUP BY
prop_name you would have got one row per prop_name, but not the latest...
ORDER BY action_date DESC makes the result come in descending action_date
order, but the individual 'hidden rows' behind each 'group row' may have a
different order. If you select MAX(action_date) you will get the latest date
for each group/ID/prop_name.

Do you want _one_ row, or do you want one row for each prop_name, multiple
rows?

Also, there seems to be some syntax errors...

I think you should replace the last two lines with this:

 action_date> '".date("Y-m-d")."'-INTERVAL 12 MONTH order by action_date
desc limit 1";

(Removed bad "(" and ")", changed a "," to a "-", removed GROUP BY clause,
inserted LIMIT clause. Not tested.)

> PS, This is for a PHP page, but I guess it won't matter right?

That is correct. Actually, you shold try to remove the php-stuff and test
the plain sql in the mysql client when you need to experiment and/or find
bugs in your queries. It is faster/easier, it helps eliminating problems
related to php, it's a great way to learn sql, and when you post your code
to this mailinglist, it is easier for more people to read it if it is plain
sql, and more people might want to help you... :)

--
Roger


---------------------------------------------------------------------
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