---
title: "How to surface a value for more than one row in MySQL"  
description: "How to surface a value for more than one row in MySQL"  
author: "Anonymous User"  
published: 2013-05-18  
updated: 2013-05-18  
canonical: https://www.mindstick.com/forum/907/how-to-surface-a-value-for-more-than-one-row-in-mysql  
category: "mysql"  
tags: ["mysql"]  
reading_time: 1 minute  

---

# How to surface a value for more than one row in MySQL

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
I know that I can [surface](https://yourviews.mindstick.com/view/81672/threat-of-asteroids-hitting-earth-s-surface) a row in a query by using it in the ORDER BY like this :\
SELECT IF(`category` IS [NOT NULL](https://www.mindstick.com/interview/1933/what-is-not-null-constraint),`category`,"Uncategorized") AS `category` FROM `table` ORDER BY `category`="Uncategorized" DESC which will make the first row always contain "Uncategorized", however I have [multiple rows](https://www.mindstick.com/forum/160908/how-to-concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql-server) that contain it that I also want surfaced. Here are two sample sets of returned data:\
What I'm getting:\
Uncategorized[Science](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science)[Health](https://www.mindstick.com/articles/43771/mental-health-in-the-workplace)Uncategorized[Wellness](https://yourviews.mindstick.com/story/1516/5-tips-for-nurturing-children-s-mental-health-wellness)What I want:\
UncategorizedUncategorizedHealthScienceWellness\
I have tried a number of other things including a CASE and also using a conditional IF. What am I [doing wrong](https://answers.mindstick.com/qa/36736/what-are-indians-doing-wrong-on-whatsapp)?\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi John!\
You using ORDER BY clause is comparing with the column name category and not on the alias given on the column.\
Try as following\
SELECT IF(category IS NOT NULL,category,'Uncategorized') categoryFROM `table` ORDER BY IF(category IS NOT NULL,category,'Uncategorized')='Uncategorized' DESCyou can alternatively use COALESCE or IFNULL to make it shorter\
SELECT COALESCE(category, 'Uncategorized') categoryFROM `table` ORDER BY COALESCE(category, 'Uncategorized') = 'Uncategorized' DESC, category\


---

Original Source: https://www.mindstick.com/forum/907/how-to-surface-a-value-for-more-than-one-row-in-mysql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
