I have 3 tables: ARTISTS, ART and PAINTINGS
ARTISTS has columns (data):
userid (adam, betty, gil, jack, larry, steve, tyler)
full_name (firstname lastname)
ART has columns:
art_id (auto number created when new art_name added via application)
art_name (name of piece of art entered)
designed_by (populated with userid)
PAINTINGS has columns:
paint_id (auto number created when new painting_name added via application)
painting_name (name of painting entered)
painted_by (populated with userid)
I need a sql statement for a report that will return a list of the userids, counts(art_id), and count(paint_id) .
Some userids will exist in both tables some will not. If not then count = 0.
Would like result set format to look like this: artist ART_CNT PAINT_CNT
adam 1 5
betty 3 0
gil 4 4
jack 6 0
larry 2 2
steve 0 9
tyler 3 7
I can get the userids and counts from each table but don't know how to join or merge the sql to get the result set format of 3 columns from one query. Is this possible???
Here are the seperate select statements:
SELECT designed_by, Count(art_id)
FROM ART
GROUP BY designed_by
SELECT painted_by, Count(paint_id)
FROM PAINTINGS
GROUP BY painted_by
Thanks for your help in advance.
4 2546 Delerna 1,134
Recognized Expert Top Contributor
Try this -
SELECT userid as artist,ART_CNT,PAINT_CNT
-
FROM ARTISTS
-
LEFT JOIN
-
( SELECT designed_by, Count(art_id) as ART_CNT
-
FROM ART
-
GROUP BY designed_by
-
) b on a.userid = b.designed_by
-
LEFT JOIN
-
( SELECT painted_by, Count(paint_id) as PAINT_CNT
-
FROM PAINTINGS
-
GROUP BY painted_by
-
) c on a.userid = c.painted_by
-
LEFT JOIN is allowed in SQL server but I don't think it will work in access
I think it should be either LEFT OUTER JOIN or LEFT INNER JOIN
Can't remember which as I havn't used access in a while
Thanks for the fast reply. What do the a, b, c reference?
b on a.userid = b.designed_by
When executing it, an error comes back as invalid identifier "b"
Delerna 1,134
Recognized Expert Top Contributor
the a b and c are alias's for the table and subqueries
I did that just to make my typing easier in the post
the alias shuld be recognizable by access. Check your query carefully
it seems you may have left the alias off
Delerna 1,134
Recognized Expert Top Contributor
No, sorry I left the alias off the table
this bit
SELECT userid as artist,ART_CNT, PAINT_CNT
FROM ARTISTS
should be
SELECT userid as artist,ART_CNT, PAINT_CNT
FROM ARTISTS a
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: dan |
last post by:
i have 2 tables that i want to count
TABLE 1
categories
--id
--name
forum_comments
--id
--category_id
|
by: Jason |
last post by:
I need to populate a table from several sources of raw data. For a
given security (stock) it is possible to only receive PARTS of
information from each of the different sources. It is also possible
to have conflicting data.
I am looking to make a composite picture of a given security using the
following rules:
1) The goal is to replace all NULL and Blank values with data
|
by: Matik |
last post by:
Hello everyone,
Small and (I think) very simple quesiton;-) which makes me creazy.
Let's say I have two tables listed below:
T1
====
IDX
====
1
|
by: tdmailbox |
last post by:
I have a database with three tables
tbl_listings - listings of houses on for sale
tbl_intersted - table which tracks if a user is interested in the
listing, it has two columns mls(the key for tbl_listings) and user(user
login)
tbl_review - table which trackes if a user has reviewed the listing.
Like tbl_interested it has two columns (the key for tbl_listings) and
user(user login)
|
by: Mike Leahy |
last post by:
Hello all,
This question is related to updating tables - is there any way to calculate or
update the values in a column in a table to the values in a field produced by
a query result? An example of what I'm trying to do is below:
update (tbl_ind_mananas LEFT JOIN (select count(*) as count, (dubicacion ||
zona || manzana) as cod_manzana from tbl_censo_poblacion_1993 group by
dubicacion, zona, manzana) tbl1 on relacion = cod_manzana) as...
| |
by: Laura |
last post by:
Here's the situation:
I'm trying to use an update query to copy data from one row to another.
Here is the situation:
I have 5 companies that are linked to each other. I need to show all 5
companies on a form. 3 of the companies have common employees. I have a
table that looks like this:
|
by: p175 |
last post by:
Hi people,
I have a stored procedure that creates many Global temporary
session tables. Into each of these tables go the results of various
processing using relational division all keyed and based on a common ID
from an ID session table. So we can have various session tables with
differing results but if they contain records, they are all keyed to
the common ID.
My problem now however is how do I report the overall findings of the
|
by: chiume |
last post by:
First thank you very much for all your helps, and pls.
Ok, this is what I am trying to do:,
1) I am trying to get the number of employees that has completed all their
online training within 10 days of hire
2) All the employees that are has no exception(no pre-service training) and
has completed their checklist within 10 days
3) all the exception(pre-service) employees that has completed their
training within 70 days.
|
by: teddysnips |
last post by:
I have a simple table with the following data:
fldYear fldCode1 fldCode2
2000 ABC1 ABC12
2000 ABC1 ABC13
2001 ABC1 ABC12
2002 ABC1 ABC12
2002 ABC1 ABC13
I need to know, for every distinct combination of fldCode1 and
|
by: filmar |
last post by:
I have two tables and need to recieve counts of each groups in columns. The 1st table is necessary to recieve exactly 4 rows even if there no one match condition id the 2nd table.
It have to count if checked is equal to 1.
CREATE TABLE . (
NOT NULL ,
) ON
GO
CREATE TABLE . (
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |