0

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

3
  • Could you please provide an example of the desired result and an example of what you're actually getting? Commented Dec 31, 2015 at 18:35
  • Distinct returns only distinct records. If there is one thing different in a row, it will be distinct. If you're getting too much back, limit the fields you are pulling. Like, if you only need distinct names, just pull that column. Commented Dec 31, 2015 at 18:37
  • @CindyMeister, Yes, check it out following link- drive.google.com/file/d/0B5SxUM9G7rObMWpBNC1sbDltVU0/… in my query I am not using distinct. In snap, you can see there are some duplicate entry. I wanna remove duplicate entries.. Commented Dec 31, 2015 at 18:40

3 Answers 3

2

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' 
Sign up to request clarification or add additional context in comments.

4 Comments

Well, I want to fetch all entries from database alongside with Distinct the titles of my entries. Is that possible?
Showing some sample data and your expected result would likely help us help you more quickly.
^^ I agree .. You didn't pose that in your OP ... Show us a couple of example rows (with duplicate data) and what the desired output should look like.
I have edited my post .. Was that what you were looking for?
1

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

1 Comment

In my case, GROUP BY is working nicewhile while DISTINCT ON has some sort of errors.
0

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.

2 Comments

if you are using GROUP BY without any aggregate function(s) then it will act the same as DISTINCT, so in this case there is no difference between GROUP BY and DISTINCT. Some would argue that in this case it's OK because "it works". So does cutting paper with a knife .. But scissors are the correct tool :-)
Well, I believe so also that literally no difference between DISTINCT and GROUP BY, however, for me GROUP BY is working nicely. TQ

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.