Re: Problem whith query in query
| From: | Marek Kilimajer | Date: | Wed, 20 Nov 2002 10:22:04 +0000 |
| Subject: | Re: Problem whith query in query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125211@lists.php.net to get a copy of this message | ||
you can use temporary tables:
CREATE TEMPORARY TABLE tmp_name SELECT SELECT MAX(ii.identifiseringid) AS max_ii
FROM identifisering as ii
GROUP BY dprosjekt
then:
SELECT * FROM identifisering as i, tmp
WHERE i.identifiseringid='123' AND i=identifiseringid=tmp.max_id;
Lars Espelid wrote:
Hello, I need some help whith a mysql-query. Can anyone help? Is there a good newsgroup for mysql? Identifiseringid is the primary key of the table identifisering and is autoincrement. There is also a coloumn named dprosjekt in identifisering and some other coloumns. dprosjekt has the same value for several tuples. For each unike dprosjekt I want to print the record where identifiseringid is max. I tought this would work, but it won't: SELECT * FROM identifisering as i WHERE i.identifiseringid=(SELECT MAX(ii.identifiseringid) FROM identifisering as ii GROUP BY dprosjekt); also tried: SELECT * FROM identifisering as i WHERE i.identifiseringid IN (SELECT MAX(ii.identifiseringid) FROM identifisering as ii GROUP BY dprosjekt); When I split the query they work: SELECT * FROM identifisering as i WHERE i.identifiseringid='123'; SELECT MAX(ii.identifiseringid) FROM identifisering as ii GROUP BY dprosjekt; Thanks, Lars