473,382 Members | 1,357 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,382 software developers and data experts.

union query, different WHERE, same table

Hi, this is my first post.
I use Access XP.

I have a single table called Movies containing the following fields:
ID, Title, Genre, Rating, Location, Date

I want a datasheet with the Titles that have a date sorted in Descending order by date, then the Titles that don't have a date sorted by Title in Ascending order.

I have this:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Title] & " " & "(" & [Rating] & ")" AS Expr1
  2. FROM Movies
  3. WHERE (((Movies.Date) Is Not Null) AND ((Movies.Genre)="Drama"))
  4. ORDER BY Movies.Date DESC
  5. UNION ALL
  6. SELECT [Title] & " " & "(" & [Rating] & ")" AS Expr1
  7. FROM Movies
  8. WHERE (((Movies.Date) Is Null) AND (((Movies.Genre)="Drama"))
  9. ORDER BY Movies.Date ASC;
I keep getting an error about the order by clause not containing fields that are in the select clause.

What am I doing wrong?
Thanks,
Chuck
Jan 18 '09 #1
3 3987
I've solved it!
The proper code should be:
Expand|Select|Wrap|Line Numbers
  1. SELECT Title, Rating, Date
  2. FROM Movies
  3. WHERE (((Movies.Genre)="Drama")) AND (((Movies.Date) Is Not Null))
  4. UNION ALL SELECT Title, Rating, Date
  5. From Movies
  6. WHERE (((Movies.Genre)="Drama")) AND (((Movies.Date) Is Null))
  7. ORDER BY Date DESC , Title;
  8.  
It's just a simple matter to format my report now, and that is done.
Yea ME!
Jan 18 '09 #2
NeoPa
32,556 Expert Mod 16PB
You've posted your question in the "insights" area.

I've moved it to the "questions" area so that it may get some interest.
Jan 19 '09 #3
NeoPa
32,556 Expert Mod 16PB
I suspect you don't need anything quite so complicated.

Try this :
Expand|Select|Wrap|Line Numbers
  1. SELECT [Title],
  2.        [Rating],
  3.        [Date]
  4.  
  5. FROM Movies
  6.  
  7. WHERE [Genre]='Drama'
  8.  
  9. ODER BY [Date] DESC,
  10.         [Title]
Jan 19 '09 #4

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

Similar topics

4
by: shaun palmer | last post by:
when or Where do you use a union query ? how can I wright sql, tblPopulation,* tblcustomer,* one to one with all the appropriate attributes(field). Your help would be greatly...
2
by: Lyn | last post by:
Hi, How do you bind the output columns from a UNION query when the fields from the two tables have different names? Consider this query (WHERE clauses omitted)... SELECT SurnameBirth,...
5
by: Lyn | last post by:
This one is difficult to explain, so I will cut it down to the basics. I have a major table 'tblA' which has an autonum field 'ID-A' as primary key (of no significance to users). 'tblA' contains...
2
by: mattytee123 | last post by:
I have about 20 tables, of which I would like to do a union query and count of how many of each different code there is? The simplified verson of the table is structured like this. Code ...
2
by: marco | last post by:
Dear List, as it seems, MS SQL as used in Access does not allow a select INTO within a UNION query. Also, it seems that a UNION query can not be used as a subquery. Maybe my (simplified)...
3
by: mikes | last post by:
I have 2 separate queries, which effectively are the same except they draw data from separate tables. Both tables are (design-wise) identical, only the data is different. for each query, there are...
2
by: Thomas | last post by:
Hi All. I think that if I explain the database layout first it may be easier to ask my question. Table Name Field Name Test TestCode Description SpecimenRequirements FeeSchedule TestCode...
7
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
2
by: cephal0n | last post by:
Hi All! First of I apologize for my previews post needing help on union select and not providing so more explanation, but thank you very much for your opinion and sugestion. I have thought about my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.