-1

I am tryimg to count the number of rows returned from a mysql query using the code below. I cannot get the count despite trying many things. Could the problem be distinct vales. Here is my query

SELECT DISTINCT SUBSTRING_INDEX(location,'>',-2), count(*) as location FROM tablename 
0

1 Answer 1

0

Use the count() as the following:

SELECT COUNT(DISTINCT column_name) FROM table_name;

May be the following queries would answer exactly what you want.

SELECT COUNT(DISTINCT SUBSTRING_INDEX(location, '>', -2)) as location 
FROM table_name;

Or

SELECT COUNT(DISTINCT location) as total 
FROM table_name
WHERE SUBSTRING_INDEX(location, '>', -2) != location;
Sign up to request clarification or add additional context in comments.

2 Comments

Do you think this question might have been asked on Stackoverflow before? Basic questions are almost always duplicates, please flag accordingly.
It has not been exactly answered. I think so. I didn't find myself any answer that can satisfy this one. I've your words in my head. So don't worry!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.