开发者

Duplicate rows in MySQL select statement

开发者 https://www.devze.com 2023-02-28 20:27 出处:网络
I have the following query: SELECT word, count FROM t_word t JOIN t_counter tc ON t.word_id = tc.id Which produces something like:

I have the following query:

SELECT word, count
FROM t_word t
JOIN t_counter tc
ON t.word_id = tc.id

Which produces something like:

'cab', 2
'capital', 3
'new york', 2

What i want to do, is have the results show up like this:

'cab',
'cab'
'capital',
'capital',
'capital', 
'new york',
'new york'

So that the count column, actually duplicates that row for my query. I'm not entirely sure if this is possible, as I haven't played much wi开发者_开发问答th loops in MySQL... Any guidance is much appreciated!.


Select T.word
From t_word As T
    Join    (
            Select 1 As Num
            Union All Select 2
            Union All Select 3
            ) As Numbers
        On Numbers.Num <= T.count

If count actually comes from the counter table, then you would do something like:

Select T.word
From t_word As T
    Join t_counter As TC
        On TC.id = t.word_id
    Join    (
            Select 1 As Num
            Union All Select 2
            Union All Select 3
            ) As Numbers
        On Numbers.Num <= TC.count
0

精彩评论

暂无评论...
验证码 换一张
取 消