Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Microsoft Query - reference to subquery alias

Hi
I'm having problems creating queries to MySQL database with MS Query.
For example the following query:

SELECT orders.id AS id,
hours.hourssum AS hourssum
FROM
orders LEFT JOIN
(SELECT job.id AS id, sum(job.hours1) AS hourssum FROM job GROUP BY
job.id) AS hours ON orders.id=hours.id
WHERE orders.id = '981382';

gives me an error: "Unknown column hours.hourssum in 'field list'".
Same query works in MySQL Query Browser just fine. I know that the
query can be done a bit differently so it works in MS Query, but this
query is just an example of the problem I'm having.

The problem is that MS Query doesn't doesn't recognize the subquery
alias "hours". Is there a way around this problem or does MS Query
have some kind of special syntax for these situations?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Microsoft Query - reference to subquery alias

My guess is the problem is with '981382'. This number is in single quotes
which means it is being treated as a string instead of a number. I would
thing this is hours which need to be divided by 24 to get days or the single
quotes removed. O r move the single quotes around the whole statement

WHERE 'orders.id = 981382'



" wrote:

Hi
I'm having problems creating queries to MySQL database with MS Query.
For example the following query:

SELECT orders.id AS id,
hours.hourssum AS hourssum
FROM
orders LEFT JOIN
(SELECT job.id AS id, sum(job.hours1) AS hourssum FROM job GROUP BY
job.id) AS hours ON orders.id=hours.id
WHERE orders.id = '981382';

gives me an error: "Unknown column hours.hourssum in 'field list'".
Same query works in MySQL Query Browser just fine. I know that the
query can be done a bit differently so it works in MS Query, but this
query is just an example of the problem I'm having.

The problem is that MS Query doesn't doesn't recognize the subquery
alias "hours". Is there a way around this problem or does MS Query
have some kind of special syntax for these situations?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Microsoft Query - reference to subquery alias

On 1 joulu, 18:37, Joel wrote:
My guess is the problem is with *'981382'. *This number is in single quotes
which means it is being treated as a string instead of a number. *I would
thing this is hours which need to be divided by 24 to get days or the single
quotes removed. *O r move the single quotes around the whole statement

WHERE 'orders.id = 981382'


Well, that's not really the problem. In this case the id has to be in
single quotes, because some id's are in string format.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Microsoft Query - reference to subquery alias

On 2 joulu, 08:17, wrote:
On 1 joulu, 18:37, Joel wrote:

My guess is the problem is with *'981382'. *This number is in single quotes
which means it is being treated as a string instead of a number. *I would
thing this is hours which need to be divided by 24 to get days or the single
quotes removed. *O r move the single quotes around the whole statement


WHERE 'orders.id = 981382'


Well, that's not really the problem. In this case the id has to be in
single quotes, because some id's are in string format.


I solved the problem. Following query works fine:

SELECT orders.id AS id,
hours.hourssum AS hourssum
FROM
(orders) LEFT JOIN
(SELECT job.id AS id, sum(job.hours1) AS hourssum FROM job GROUP BY
job.id) AS hours ON orders.id=hours.id
WHERE orders.id = '981382';

So the only thing that is different is brackets around orders-table
right after FROM keyword.
I don't know why it worked fine without brackets in MySQL Query
Browser. Maybe it's because I'm using ODBC to connect to database from
Excel.

Thanks anyway
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003, Microsoft Query - reference to subquery alias Finnman Excel Discussion (Misc queries) 1 December 2nd 08 11:21 AM
SQL query removes alias BusterC Excel Discussion (Misc queries) 1 February 8th 06 04:35 PM
MS Query - Alias syntax David P Excel Worksheet Functions 3 February 16th 05 09:29 AM
Column Alias in MS Query Diana[_6_] Excel Programming 2 May 19th 04 07:36 PM
Microsoft Query - how to reference a cell value in a filter Dan Excel Programming 1 December 13th 03 01:28 AM


All times are GMT +1. The time now is 09:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"