473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Access SQL ORDER BY putting NULL values last in query

Hello,

NOTE: Im working in MS Access 2003, only results in this SQL/database (not mysyl, MSSQL etc)

I want to be able to ORDER an SQL query and put the NULL values last.

I have a basic databse:
Table name: PeopleTable
Field names: TableID, PersonField, PersonID

The aim is to order by PersonID and put the NULL values last

I use the orderby SQL statement
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM PeopleTable ORDER BY PersonID;
and it shows the results ordered by the

PersonID however the NULL values are first.

The desired result is to have similar results to the above query but ensure the NULL values are displaed last?

How can i achieve this is MS Access 2003? Can someone provide me with the SQL using the said example?

Thanks,

Jac
Dec 20 '12 #1

✓ answered by Rabbit

Or if you want the same order but just with the nulls at the end, order by the Nz() function result of the field where the second parameter is all Z's or something similar.

3 9505
Jerry Maiapu
259 100+
Just add the keyword "Desc" to sort the Id from highest to null like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM PeopleTable ORDER BY PersonID DESC;
Dec 20 '12 #2
Rabbit
12,516 Expert Mod 8TB
Or if you want the same order but just with the nulls at the end, order by the Nz() function result of the field where the second parameter is all Z's or something similar.
Dec 20 '12 #3
NeoPa
32,556 Expert Mod 16PB
No option to comment when setting Best Answer, but that hits the nail squarely on the head. An example, in case it's needed, would be :
Expand|Select|Wrap|Line Numbers
  1. SELECT   *
  2. FROM     [PeopleTable]
  3. ORDER BY Nz([PersonID],'zzzzz')
Dec 20 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Joshua Ruppert | last post by:
A section of the documentation for the isSet() function states: Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant. Where would you encounter a NULL byte? Is a null...
2
by: C. Lo | last post by:
Hi I have a situtation where a query returns a table in which some of the values are null. When I sort the results, the null values are treated as greater than the other numerical results. Is it...
12
by: Irene | last post by:
Hi all again, Well, I have my Athletics database with Athletes, Competitions, Scores tables. I have a ranking query where I get back the list of the competitions-athletes and scores...
6
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
3
by: John | last post by:
I've read several prior posts in this group about using nz() to convert null values to zero; however, I'm not sure how/where to implement this function in my crosstab query. The crosstab query...
3
by: JOEP | last post by:
What do I need to do to allow an append query to post null values to records in a field of the destination table? Basically I want to allow records with null values to post to the table. The append...
1
by: mar10 | last post by:
I have a form that has a drop down box on it which allows the user to select a YEAR. If the user makes a selection I have a subform that is driven by a query that will select the YEAR that the...
5
by: ernestb08 | last post by:
I have a Customers Table with the following field names. C_FirstName C_LastName C_MiddleI .. .. .. .. ..
1
by: sreemati | last post by:
ssue: ------ I am working on a health care system and currently facing problem with NULL values being introduced as part of my SQL query. What is the query trying to do? The query is trying to...
6
by: JenniferM | last post by:
I'm creating a form where you can input either some or all of a person's information in order to sort through the matching records in the table TblPatientDemographics. I'm searching based on ID...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.