Using Oracle SQL, I have a column of strings called "title" in a table called OBJECT. Words are separated by spaces.
I want to write a query count how many titles have the same first word as other titles in the table. I want to output the word, and a count of how many entries begin with that word as FIRSTWORD, WORD_COUNT. E.G.
FIRSTWORD WORD_COUNT
Word1 23
Word2 15
I am using both SUBSTR and INSTR to get the first word of each entry, and regexp_count to try and count the number of times it appears. So far, I can get it to output a list of the first words, but my count is always 0:
SELECT
(SUBSTR(title, 0, INSTR(title, ' ')-1)) AS FIRSTWORD,
(REGEXP_COUNT(title, INSTR(title, ' ')-1)) AS WORD COUNT
FROM OBJECT GROUP BY title;