简体   繁体   中英

How to Sort the rows in Ms-Access Table using only 1 row?

I am trying to sort one of my tables in my database ms-access using only 1 column. the value of the column is like this:

PartMaterial
---------------------
C90X61Y13B
C90X61Y13D
C90X61Y1B
--------------------

I did not put all the data in here because it's too many.

but i tried this sql:

SELECT DISTINCT PartMaterial FROM tblMaterialMark ORDER BY PartMaterial ASC

but the result is like this:

PartMaterial
---------------------
C90X61Y13B
C90X61Y13D
C90X61Y1B
--------------------

which is wrong, because C90X61Y1B should be the first in line.

Correct output:

PartMaterial
---------------------
C90X61Y1B
C90X61Y13B
C90X61Y13D
--------------------

How can I possibly sort these items in ascending order with the integer and string combined?

That is alphabetical. Perhaps you want by length:

ORDER BY LEN(PartMaterial),  PartMaterial

If this doesn't work with SELECT DISTINCT , you can try GROUP BY instead:

SELECT PartMaterial
FROM tblMaterialMark 
GROUP BY PartMaterial
ORDER BY LEN(PartMaterial),  PartMaterial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM