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

MS Access SQL Statement. Help???

Help me write this for MS access, I'm used to Oracle -

SELECT Users.*, group_1, group_2, group_3

from

(select UserInGroup.UserID,

max(decode(GroupID, 1, GroupID, null)) as group_1,

max(decode(GroupID, 2, GroupID, null)) as group_2,

max(decode(GroupID, 2, GroupID, null)) as group_3

from Users u, UserInGroup g

where u.UserID = g.UserID

and u.GroupID in (1,2,3)

group by u.UserID
)

May 1 '06 #1
3 2890
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I don't believe that query would work in Oracle (as well as Access),
you've not added the Users table in the main query's FROM clause.

SELECT Users.*, group_1, group_2, group_3

from

(select g.UserID,

max(IIf(GroupID=1, GroupID, null)) as group_1,

max(IIf(GroupID=2, GroupID, null)) as group_2,

max(IIf(GroupID=2, GroupID, null)) as group_3

from Users u INNER JOIN UserInGroup g ON u.UserID = g.UserID

where u.GroupID in (1,2,3)

group by u.UserID

) AS A

INNER JOIN Users ON A.UserID = Users.UserID

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRFfluYechKqOuFEgEQK4kQCeK5/OG7uRsrkLBcUEHqqlO4g7LmQAnRsu
5g9/VF6CSf02db0HscLV6N3u
=Wu5n
-----END PGP SIGNATURE-----
sa******@gmail.com wrote:
Help me write this for MS access, I'm used to Oracle -

SELECT Users.*, group_1, group_2, group_3

from

(select UserInGroup.UserID,

max(decode(GroupID, 1, GroupID, null)) as group_1,

max(decode(GroupID, 2, GroupID, null)) as group_2,

max(decode(GroupID, 2, GroupID, null)) as group_3

from Users u, UserInGroup g

where u.UserID = g.UserID

and u.GroupID in (1,2,3)

group by u.UserID
)

May 2 '06 #2
MG -

Thanks so much for the help!!! I'm hopefull we can resolve this today.

I've tried the above SQL statement and get the following:

"YOu tried to execute a querry that does not include the specific
expression 'UserID' as part of an aggregate function."

And I'm clueless as to what that means. Any ideas?

Additionally, Access rewrote the statement a bit when I brought it into
design view and then gave me the following error:

"The Microsoft Jet engine does not recognize 'Users.*' as a valid field
name or expression."

SELECT Users.*, group_1 AS Expr1, group_2 AS Expr2, group_3 AS Expr3
FROM [select g.UserID,
max(IIf(GroupID=1, GroupID, null)) as group_1,
max(IIf(GroupID=2, GroupID, null)) as group_2,
max(IIf(GroupID=2, GroupID, null)) as group_3
from Users AS u INNER JOIN UserInGroup AS g ON u.UserID = g.UserID

where u.GroupID in (1,2,3)
group by u.UserID
]. AS A;

To sum up, just to make sure I'm explaininig myself correctly:

1 record returned from querry per UserID with its
GroupID's in additional columns (either null or with value as needed).
Ergo - trying to match each UserID up with all of its GroupID's and
returned in ONLY one record.

thanks everyone for your help.

S.

May 3 '06 #3
Change the line

FROM (select g.UserID

to

FROM (select u.UserID

and add this line to the bottom of the query (remove the ending
semi-colon ";" first):

INNER JOIN Users ON A.UserID = Users.UserID

May 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Penny | last post by:
Hi all, Thanks again guys for the help re Select Case. I might trouble you with something else: I use this SQL in the Access query builder to return a single AirRate: SELECT AirRate FROM...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
14
by: wolftor | last post by:
1) Is there a free runtime version of Access available that is more recent than the one for Access 2000? 2) If I create an application (MDE) in A2K, will it run on all later versions of Access?...
2
by: edo | last post by:
100 Day Analysis Following is a summary of articles spanning a 100 day period, beginning at 10 Sep 2003 06:41:30 GMT and ending at 19 Dec 2003 04:09:06 GMT. Notes ===== - A line in the...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
3
by: SAL | last post by:
I’m fairly new to .NET. I’ve been developing in .NET for about 6 months. I have over 10 years experience with VB in general. Here’s what I have done so far: 1. Project is entirely .NET...
7
by: Cheryl Langdon | last post by:
Does anyone know if there is a way to globally turn off ALL control tips in Access 2003 using VBA code? Thanks. --- CL
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
2
by: eskelies | last post by:
So here is my issue. I have a multiple IF statement in Excel 2003, which I am trying to convert to Access 2003. My error in Access has to do with the OR function , which is taking place inside the IF...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.