Page 1 of 1

HELP with SELECTING record FROM MySQL

Posted: Sat Jan 17, 2009 1:32 am
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

Re: HELP with SELECTING record FROM MySQL

Posted: Sat Jan 17, 2009 3:11 am
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.

Re: HELP with SELECTING record FROM MySQL

Posted: Sat Jan 17, 2009 4:29 am
by VladSun
+
[sql]GROUP BY Client_id[/sql]