Forum Discussion
Combo box with "All" added to query and sorted on top.
- Oct 25, 2019
Thanks guys for helping me solve my issue. Here is my working code:
' SELECT tblCategoryList.Category As Category, "1" As ID
' FROM tblCategoryList
' UNION
' SELECT "All Tags", 0
' FROM tblCategoryList
' ORDER BY ID, Category;
Basically I created a row in SQL called ID and all records added from the tblCategoryList table are labeled 1 under ID. The Union adds the "All Tags" and under the ID column the row is identified with 0. Then I sort via ID and followed by Category. Now I can keep the order ascending and no matter what the "All Tags" remains on top.
I would make an extrta column in the query and skip it in the combobox.
SELECT tblCategoryList.id, tblCategoryList.Category
FROM tblCategoryList
UNION
SELECT 0, "All"
FROM tblCategoryList
ORDER BY tblCategoryList.id, tblCategoryList.Category;
Greetings,
Marcel
- testmutsOct 24, 2019Brass Contributor
Sorry I posted wrong SQL before. Needs to sort better :))
SELECT iif(tblCategoryList.id=0,0,"1"& tblCategoryList.Category) as zCategory, tblCategoryList.Category
FROM tblCategoryList
UNION SELECT 0,"all"
FROM tblCategoryList
ORDER BY zcategoryWith this you can skip the first column and it will work as needed.
- AmedMesaOct 25, 2019Copper Contributor
Thanks guys for helping me solve my issue. Here is my working code:
' SELECT tblCategoryList.Category As Category, "1" As ID
' FROM tblCategoryList
' UNION
' SELECT "All Tags", 0
' FROM tblCategoryList
' ORDER BY ID, Category;
Basically I created a row in SQL called ID and all records added from the tblCategoryList table are labeled 1 under ID. The Union adds the "All Tags" and under the ID column the row is identified with 0. Then I sort via ID and followed by Category. Now I can keep the order ascending and no matter what the "All Tags" remains on top.