Order By clause

S

samah

In a sample database, I have the following query.

SELECT Null As Title
FROM tblDummy
UNION ALL SELECT tlkpTitles.Title
FROM tlkpTitles
ORDER BY 1;

tblDummy is a single field table that provides null value to combo boxes
and tlkpTitle is also single field table that stores person's titles
(Mr., Mrs, Ms. etc.). What is the meaning of 1 in the Order by clause?
Even if I remove the Order By clause altogether, the query returns the
same results.

Thank you in advance.

- samah
 
R

RoyVidar

samah said:
In a sample database, I have the following query.

SELECT Null As Title
FROM tblDummy
UNION ALL SELECT tlkpTitles.Title
FROM tlkpTitles
ORDER BY 1;

tblDummy is a single field table that provides null value to combo boxes
and tlkpTitle is also single field table that stores person's titles
(Mr., Mrs, Ms. etc.). What is the meaning of 1 in the Order by clause?
Even if I remove the Order By clause altogether, the query returns the
same results.

Thank you in advance.

- samah

The ORDER BY clause isn't supposed to alter what is returned, but the
order in which the result is returned.

The ORDER BY clause of Access/Jet allows you to specify ordinal
position, in stead of column name, so in your case, using

ORDER BY Title

Should also work.
 
S

samah

RoyVidar said:
The ORDER BY clause isn't supposed to alter what is returned, but the
order in which the result is returned.

The ORDER BY clause of Access/Jet allows you to specify ordinal
position, in stead of column name, so in your case, using

ORDER BY Title

Should also work.

Learned something new again! Thank you, Roy.

- samah
 
D

Douglas J. Steele

RoyVidar said:
The ORDER BY clause isn't supposed to alter what is returned, but the
order in which the result is returned.

The ORDER BY clause of Access/Jet allows you to specify ordinal
position, in stead of column name, so in your case, using

ORDER BY Title

Should also work.

But the only reason why you'd be able to use ORDER BY Title is because the
first subselect included SELECT Null As Title.

If that had simply been

SELECT Null
FROM tblDummy
UNION ALL
SELECT tlkpTitles.Title
FROM tlkpTitles

then that first column would likely have ended up being named Expr1000, and
you would have needed to use

SELECT Null
FROM tblDummy
UNION ALL
SELECT tlkpTitles.Title
FROM tlkpTitles
ORDER BY Expr1000
 
S

samah

Douglas said:
But the only reason why you'd be able to use ORDER BY Title is because the
first subselect included SELECT Null As Title.

If that had simply been

SELECT Null
FROM tblDummy
UNION ALL
SELECT tlkpTitles.Title
FROM tlkpTitles

then that first column would likely have ended up being named Expr1000, and
you would have needed to use

SELECT Null
FROM tblDummy
UNION ALL
SELECT tlkpTitles.Title
FROM tlkpTitles
ORDER BY Expr1000

Thank you, Douglas. I got the point crystal clear now.

- samah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top