How can I prevent multiple outputs from a query?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

How can I prevent multiple outputs from a query?

Post by dominod »

Hi there 8)

Im just wondering how I can prevent the query from outputing the same name twice in a query?

Example:

If I query and it outputs:

Name- Age- Location-
Roger 23 New York
Eric 29 Miami
Eric 48 Boston

Is there a way to make it recognize that it already outputed "Eric" then make it skip the next eric so it just outputs:

Name- Age- Location-
Roger 23 New York
Eric 29 Miami

?

Thanks alot guys :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: How can I prevent multiple outputs from a query?

Post by VladSun »

First question - how do you decide which data should come out with Eric? I.e. why it is "29 Miami" and not "48 Boston"?
There are 10 types of people in this world, those who understand binary and those who don't
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Re: How can I prevent multiple outputs from a query?

Post by dominod »

Because there is one row which sais:

Eric 29 Miami

while another row sais:

Eric 48 Boston
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Re: How can I prevent multiple outputs from a query?

Post by dominod »

Solved it:

Code: Select all

(...) GROUP BY name
Post Reply