tisuchi
tisuchi

Reputation: 129

Fetch all unique data from mysql with PHP distinct

I am stuck on fetching unique data from MySql Database by PHP Distinct. I want to fetch all the data from the table but in a particular field 'ccTitle' should remove duplicate entries. My Query is as follows-

"SELECT DISTINCT(*) FROM conferencecreate WHERE ccFlag = 1 AND ccStartingDate >= '$nowTime'"

But it's not working. I discovered Distinct is working individually for a field. Is there another to solve this issue?

Let me know please.

TQ

Upvotes: 0

Views: 3704

Answers (3)

devpro
devpro

Reputation: 16117

You are looking for this query:

SELECT *
TABLE table
GROUP BY column

You can write this query with DISTINCT statement like that:

SELECT DISTINCT ON column *
FROM table

Upvotes: 1

tisuchi
tisuchi

Reputation: 129

Well, finally I found the appropriate answer for my question. Instead of using distinct, group by can be used to solve this issue.

$q = mysql_query("SELECT * FROM conferencecreate WHERE ccFlag = 1 AND ccStartingDate >= '$nowTime' GROUP BY ccTitle");

It's working for me perfectly.

Thank you all.

Upvotes: 0

Zak
Zak

Reputation: 7515

You are going to have to SELECT DISTINCT for each field you want non-duplicated data ..

IE

SELECT DISTICT ON item1,item2 *
FROM table WHERE something = 'something' 

Upvotes: 2

Related Questions