Solved

MySQL query in Access

Posted on 2014-04-11
4
358 Views
Last Modified: 2014-04-14
A collegue requested I modify this query (for MS Access) so that he gets the latest date (adate) from the projectactivity table as well as the list of projects:

original query:
SELECT * FROM projects 
WHERE projects.active='yes'

Open in new window


I gave him this query, which works well in MySQL:
SELECT * FROM projects 
LEFT OUTER JOIN (SELECT projectactivity.projectid as id,max(adate) as latestdate FROM projectactivity WHERE projectactivity.projectid='10335-2') as derivedTable ON projects.ProjectID=id
WHERE projects.active='yes' 

Open in new window


I don't use Access enough to know why this does not work for him in Access.  

NOTE:In his MS Access setup, he is connecting to the same MySQL tables that I tested my query on.  He uses Access to format the MySQL data into printable report formats.
0
Comment
Question by:Zipbang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 57

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 total points
ID: 39993904
Try this

SELECT * FROM projects 
    LEFT OUTER JOIN (
       SELECT projectactivity.projectid as id,max(adate) as latestdate 
       FROM projectactivity WHERE projectactivity.projectid='10335-2'
     ) AS derivedTable 
     ON projects.ProjectID=derivedTable.id
WHERE projects.active='yes' 

Open in new window

0
 

Author Comment

by:Zipbang
ID: 39994366
Julian,

This helps, but I think I misunderstood his request.

He wants a query that shows  all active projects (active='yes') from the projects table and the latest adate (max(adate)) for each one when adate is in the table named projectactivity

SELECT * FROM projects 
--  join on the latest date from the projectactivity table, where projectactivity.id=projects.id
WHERE projects.active='yes'
 

Open in new window


Sorry for the confusion, am I clear here?
0
 
LVL 41

Accepted Solution

by:
Sharath earned 250 total points
ID: 39995067
remove the WHERE clause and I think you missed the GROUP BY clause.
SELECT * FROM projects 
    LEFT OUTER JOIN (
       SELECT projectactivity.projectid as id,max(adate) as latestdate 
       FROM projectactivity GROUP BY projectactivity.projectid
     ) AS derivedTable 
     ON projects.ProjectID=derivedTable.id
WHERE projects.active='yes' 

Open in new window

0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 39995911
Just checking, why do you have this filter in your sub query

WHERE projectactivity.projectid='10335-2'

Will you only ever by searching on that projectid?
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question