HELP with SELECTING record FROM MySQL

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
dv_evan
Forum Commoner
Posts: 42
Joined: Wed Apr 09, 2008 8:23 am

HELP with SELECTING record FROM MySQL

Post by dv_evan »

Hello Everyone,

I would like you to assist me in solving this problem I am having extracting data from MYSQL with PHP.
I have a table in my database as seen below, I am attempting to select all the Client_id that are associated with the Project_id of '20'.


ID | Client_id | Project_id

1 | 1007 | 20
2 | 1009 | 20
3 | 1010 | 16
4 | 1007 | 20
5 | 1007 | 15
6 | 1007 | 20
7 | 1009 | 16
8 | 1007 | 20
9 | 1010 | 20
10 | 1007 | 16

I have written a select statement that looped through and extract the Client_id that relates to Project 20 with the following results: (SELECT Client_id FROM Table WHERE Project_id = 20)

1007
1009
1007
1007
1007
1010

However, I would like each Client_id that associates with '20' to only be outputted once instead of everytime they appeared , for example:

1007
1009
1010


Kindly assist me since I have been at this for more than a week.

Thanks
Dave
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: HELP with SELECTING record FROM MySQL

Post by JAB Creations »

I have discovered as I have gotten better at MySQL that if I get more then one record returned that I did not correctly write my query.

With 33 posts you should be aware by now that it's also pointless to post about code without posting code.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: HELP with SELECTING record FROM MySQL

Post by VladSun »

+
[sql]GROUP BY Client_id[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply