I have now tried the following statement:
SELECT annoncer.id,MAX(annoncer.type) AS maks,annoncer.virk_id FROM
annoncer,virksomheder
WHERE virksomheder.navn LIKE '%SomeWord%' AND virksomheder.id =
annoncer.virk_id
GROUP BY annoncer.virk_id ORDER BY virksomheder.navn

This almost works...
forget the "virksomheder" table it's not the essential here.
What i get from this is rows | id | maks | virk_id | where.

| id | - is the first known id for a given "virk_id"
| maks | - is the highes value of type for a given "virk_id"
| virk_id | - is the given virk_id

What i needed was (actually only needed the id):
| id | - where type has the highest value for a given "virk_id"

example table:
| id | virk_id | type |  ("id" is unique, "virk_id" is not unique, "type" is
not unique)
-------------------
| 1 |     23    |   1   |
| 2 |     16    |   2   |
| 3 |     23    |   4   |
| 4 |     16    |   1   |
| 5 |     33    |   3   |

What I want out of this table would be the rows with id: 2,3 and 5
2 because "virk_id" is present twice but the row with id = 2 has the highest
"type" for "virk_id" = 16.
3 because "virk_id" is present twice but the row with id = 3 has the highest
"type" for "virk_id" = 23.
5 because "virk_id" is present only once so the value of type doesnt matter.

Does this make it easier for you to see what it is I'm trying to do here?



"Aidal" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi NG.
>
> I'm sure there is somthing implemented in PHP to do this but I just cant
see
> it.
>
> I want to run through an array and remove some entries where <somthing 1>
is
> true and <somthing 2> is lower than the other entries of <somthing 1>
>
> First i thought... hmm this sounds like a linked list, I'm gonna make one.
> But I cant seem to make the list concept work properly with PHP, so I
> thought that somthing might have been made for this.
>
> Example:
>
> for ($i = 0; $i < sizeof(some_db_result); $i++) {
>     array[$i]['id'] = this_db_result_row['id'];
>     array[$i]['type']  = this_db_result_row['type'];
>     array[$i]['v_id'] = this_db_result_row['v_id'];
> }
> // (id) is unique
> // (type) is 1-4
> // (v_id) is not unique.
>
> What I want to do is to find all entries where (v_id) is the same and then
> remove all but the one where (type) has the highest value.
> How do I do this?
> Or can a SQL statement do this in a DISTINCT like way? (SELECT table.id
FROM
> table WHERE somthing is = somthing else and a lot of other stuff BUT only
> give me those where table.type has the hifgrst value)?
>
> Please... need help with this
> ~ Aidal.
>
>



-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to