# How to sort data from SQL query

**URL:** <https://forum.inductiveautomation.com/t/how-to-sort-data-from-sql-query/80812>\
**Category:** Maker\
**Tags:** perspective\
**Created:** [October 22, 2023, 12:37am UTC](https://forum.inductiveautomation.com/t/how-to-sort-data-from-sql-query/80812 "2023-10-22T00:37:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [October 22, 2023, 12:37am UTC](https://forum.inductiveautomation.com/t/how-to-sort-data-from-sql-query/80812/1 "2023-10-22T00:37:38Z")

</div>

Hi!

How can i only output i.e the [BrewDate] from this query?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/0/501c73d33801f44b6f2ed03f4906dbb551020888.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 22, 2023, 1:23am UTC](https://forum.inductiveautomation.com/t/how-to-sort-data-from-sql-query/80812/2 "2023-10-22T01:23:21Z")

</div>

The best way is to create a new named query with only one column.

```auto
SELECT TOP 1000
    [BrewDate]
FROM ...

```

Alternatively, you can use an expression transform as you are doing.  
`columnRearrange({value}, 'BrewDate')`  
but this may be slower than using the correct query in the first place.

[https://docs.inductiveautomation.com/display/DOC81/columnRearrange](https://docs.inductiveautomation.com/display/DOC81/columnRearrange)

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [October 22, 2023, 10:37am UTC](https://forum.inductiveautomation.com/t/how-to-sort-data-from-sql-query/80812/3 "2023-10-22T10:37:31Z")

</div>

Thank you, this seems to work. Only problem it how can i format the result? Now it shows like this:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/8/e82b90e04dce5fd0e907f6bac4399d656e2f9392.png)

I want it to show "American Blonde".

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 22, 2023, 12:32pm UTC](https://forum.inductiveautomation.com/t/how-to-sort-data-from-sql-query/80812/4 "2023-10-22T12:32:40Z")

</div>

You have a 1000 row binding on a label which can only display one piece of text. Your query indicates that you are expecting that many results but your result above shows that you only got one. Is there something else wrong?

To show one value in the label change your named query to Scalar query type (which just returns a single value) and use

```auto
SELECT TOP 1
    [BrewDate]
FROM ...

ORDER BY [BrewDdate] DESC

```

if you want the most recent BrewDate (otherwise what you get will be kind of random depending on the order of the records in the DB).

If you want to display more than one then bind your original query to a table component instead.

You can right-click on the `label.text` binding, copy binding, right-click on the table data property and paste binding there.
