-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 
user1823053
  • 67
  • 1
  • 2
  • 8

1 Answers1

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;
unclexo
  • 3,691
  • 2
  • 18
  • 26
  • Do you think this question might have been asked on Stackoverflow before? Basic questions are almost always duplicates, please flag accordingly. – mickmackusa Jan 26 '20 at 08:19
  • 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! – unclexo Jan 26 '20 at 08:43