Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query to alphabetically

Status
Not open for further replies.

imms50

Technical User
Feb 13, 2002
15
US
hi!
I want to write query to sort two columns alphabetically at the same time which are in the same table (Using Access 2000).Can anybody please advise how?


Thanks everyone
 
Dear imms50,
Go to:
Queries|New|Design View|Show Tables|
Add Your Table to Query Main Window|
Drag the 2 Fields you wish to sort by to the grid (ones to the Left sort before ones to the Right)|
Put insertion point in the Sort: cell under each field you added and click the arrow at the right and select one of the options in the Drop-down list.
Close and save your query.

When this query is run it will display only the two columns,
if you wish to see the whole Table then in Design View of the Query drag the * to the grid and unclick the Show: box under the 2 Fields you added first time but leave the tick under the *.
Close and save your query again and run it.

HTH
 
Dear James:

Thanks for the suggestion but that is not what I wanted.
I know this cannot be done but I was just asking if we can write a query in which we can sort both the columns together.

Like for Example, Suppose Column 1 consists the names starting with B,C,A,F,G. and Column 2 consists the names starting with C,A,D,G,H. So with reference to that example y question would be, Can we write a query qith the following output: A from Col1,A from Colum2,B from Col 1, C from Col 1, C from Column 2, D from Column 2, F from Col 1, G from column1 , G from column 1, and finally H from column 2.

I know that sounds a little bit illogical but I was just curious if it can be done that way
 
I see what you mean.
I guess a temporary table might suit but I will leave it to the more competent to advise you on that
Good Luck
Jim
 
Here's how you do it.

Assume you have one table (Table1) with two fields (field1, field2). You have four records that look like:

field1 field2
a c
d a
c b
b d

Use the following UNION query to accomplish sorting both fields and giving you eight rows:

SELECT Table1.field1 AS MyField
FROM Table1
UNION ALL
SELECT Table1.field2 AS MyField
FROM Table1
ORDER BY MyField;

Hope that helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top