/    Sign up×
Community /Pin to ProfileBookmark

mysql trouble…

Hi,

I have a trouble with the group function using php Mysql. Performing the following :

[code=php]“SELECT * FROM table WHERE owner LIKE’$username’ GROUP BY date”[/code]

returns the first row fitting the condition even if several rows do fit the condition.

What I would need is to return the maximum of each column of all the rows fitting the condition (I have lots of columns).

For instance, with the following table,

id=1 – owner=you – bla1=aaa – bla2=[COLOR=”red”]222[/COLOR] – bla3=222
id=2 – owner=you – bla1=[COLOR=”Red”]bbb[/COLOR] – bla2=111 – bla3=[COLOR=”red”]333[/COLOR]

I would like to get :

—–> owner=you – bla1=[COLOR=”Red”]bbb[/COLOR] – bla2=[COLOR=”red”]222[/COLOR] – bla3=[COLOR=”red”]333[/COLOR]

Can anybody help me ?

Many thanks in advance!!!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@sstalderSep 01.2008 — "SELECT * FROM table WHERE owner LIKE '%$username%' GROUP BY date"
Copy linkTweet thisAlerts:
@chazzySep 02.2008 — you need to use the aggregate MAX on each column.

<i>
</i>select max(bla1), max(bla2) ...
from table where owner= 'some user' group by date;
×

Success!

Help @patimages spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...