473,405 Members | 2,404 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,405 software developers and data experts.

Order By twice?

I am creating a database to store a wedding invite list. I am storing fname, lname, phone, street, city, state, zip.

Now i want to create a query that will return all the people in the list, i want to order it by people whos addresses are not in the database first in alphabetical order by last name, and then everyone who is in the the database with an address by alphabetical order by last name. Heres what i have so far:

SELECT fname, lname, phone, street
FROM tblGrooms
ORDER BY street, lname;

Now this will return exactly what i want, but it sorts the second half (the list of names that DO have addresses) by address NOT last name. How can i fix this?

Im sure this is a really simple fix and im just over looking it! Please help!
May 11 '07 #1
3 1622
MMcCarthy
14,534 Expert Mod 8TB
This question has been posted in the Articles section and is being moved to the Access forum.

ADMIN
May 11 '07 #2
ADezii
8,834 Expert 8TB
I am creating a database to store a wedding invite list. I am storing fname, lname, phone, street, city, state, zip.

Now i want to create a query that will return all the people in the list, i want to order it by people whos addresses are not in the database first in alphabetical order by last name, and then everyone who is in the the database with an address by alphabetical order by last name. Heres what i have so far:

SELECT fname, lname, phone, street
FROM tblGrooms
ORDER BY street, lname;

Now this will return exactly what i want, but it sorts the second half (the list of names that DO have addresses) by address NOT last name. How can i fix this?

Im sure this is a really simple fix and im just over looking it! Please help!
You could experiment with a UNION Query, something along the lines of:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblEmployee.LastName, tblEmployee.FirstName, tblEmployee.PhoneNumber, tblEmployee.Address
  2. FROM tblEmployee
  3. WHERE tblEmployee.Address Is Null
  4.  UNION SELECT tblEmployee.LastName, tblEmployee.FirstName, tblEmployee.PhoneNumber, tblEmployee.Address
  5. FROM tblEmployee
  6. WHERE tblEmployee.Address Is Not Null
  7. ORDER BY tblEmployee.LastName;
May 12 '07 #3
NeoPa
32,556 Expert Mod 16PB
I am creating a database to store a wedding invite list. I am storing fname, lname, phone, street, city, state, zip.

Now i want to create a query that will return all the people in the list, i want to order it by people whos addresses are not in the database first in alphabetical order by last name, and then everyone who is in the the database with an address by alphabetical order by last name. Heres what i have so far:

Expand|Select|Wrap|Line Numbers
  1. SELECT fname, lname, phone, street
  2. FROM tblGrooms
  3. ORDER BY street, lname;
Now this will return exactly what i want, but it sorts the second half (the list of names that DO have addresses) by address NOT last name. How can i fix this?

Im sure this is a really simple fix and im just over looking it! Please help!
You've only told us half the story.
How can you sort by the last name if the entry doesn't even exist in the database?
If you can express the question accurately, then I'm sure someone can help you with an answer. I suspect it won't be as complicated as using a UNION query in this case, but we can only guess if you don't share the question with us.
May 14 '07 #4

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

Similar topics

3
by: ASobol | last post by:
//code.begin() #include <iostream> int g (int i) { static const int j = i; return j; } int main (int, char**)
7
by: publictom | last post by:
Is the following statement true? "It is required that the operands to an operator be fully evaluated before the operator itself is evaluated." The only way I can think of that it would be...
3
by: Greg Strong | last post by:
Hello All, Is the only solution to an update query which requires the records in a certain order to dump the records into a temp table in the required order, then do the update query? I've...
20
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2....
4
by: Mike Nolan | last post by:
I'm trying to create a summary log by hour. Here's the query (somewhat simplified): select to_char(mtrantime,'mm-dd hh AM') as datetime, count(*) as tot from memtran group by datetime order...
9
by: John Smith | last post by:
I've been playing with splint, which returns the following warning for the code below: statlib.c: (in function log_norm_pdf) statlib.c(1054,31): Expression has undefined behavior (left operand...
5
by: ibiza | last post by:
Hi all, I use VB.NET (C# would do the same) and GDI+ to draw on a form. I'd like to know if it is possible to set the z-order when we draw something...Let's consider that simplified case : '...
54
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of...
2
by: EzeeGoN | last post by:
Using Flash8 Actionscript 2.0 i am looking for a method to generate sequential numbers in a random order (not using the same number twice) can anyone help please?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.