Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Example

My query is:

SELECT code_CAT FROM categories WHERE id_code IN(14,14,14,14);

output is:

53724

Only one row.

Instead I want this output:

53724
53724
53724
53724

How can I achieve this? I want this because I need to use the records on an Excel Spreadsheet.

share|improve this question
    
I saw a good example in tutorialspoint.com/mysql/mysql-in-clause.htm But I feel, your question is not complete to give you an answer. Can you paste the output of following SQL query into question: SELECT * FROM categories WHERE id_code IN(14,14,14,14); –  Suku Jan 3 '13 at 15:38
1  
There's only one row returned because there is only one row in the table categories where code_CAT has the value 14. Repeating that same id_code value in the IN doesn't change that. I don't follow why, if there is only one such row in the table, you want it repeated four times. Could you elaborate? –  mdoyle Jan 3 '13 at 17:48
add comment

migrated from serverfault.com Jan 3 '13 at 16:27

This question came from our site for professional system and network administrators.

1 Answer

If you really need it (I don't get why though), you can do

SELECT code_CAT 
FROM categories a
INNER JOIN 
(
  select 14 as id_code
  UNION ALL
  select 14
  UNION ALL
  select 14
  UNION ALL
  select 14
)b ON (a.id_code = b.id_code)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.