https://www.youtube.com/watch?v=iKQB4WtN-C4
DROP TABLE IF EXISTS Combinations
;
CREATE TABLE Combinations
(
Word varchar(100)
)
;
INSERT INTO Combinations
VALUES
('A'),
('B'),
('C'),
('D'),
('-'),
('Apple'),
('Ball'),
('Cat'),
('Dog'),
('-5515'),
('-5255'),
('Ant')
SELECT * FROM Combinations
-- Approach 1
WITH cte_alphabet as (
select
*
from Combinations
where word REGEXP '^.
SUBQUERY
```sql
-- Approach 2
select *
from combinations a
left join (select * from combinations where length(word)>1) b ON a.word = left(b.word,1)
where b.word is not null
```)
,cte_words as (
select
*
,left(word,1) as first
from combinations
where word NOT REGEXP '^.
[[SUBQUERY]]
{{CODE_BLOCK_2}}
)
select c.word as Alphabet,cw.word as Word from cte_alphabet c join cte_words cw on c.word = cw.first
order by word
[[SUBQUERY]]