473,405 Members | 2,176 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,405 software developers and data experts.

sql query help

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:
Expand|Select|Wrap|Line Numbers
  1. SELECT designed_by, Count(art_id)
  2. FROM ART
  3. GROUP BY designed_by
  4.  
Expand|Select|Wrap|Line Numbers
  1. SELECT painted_by, Count(paint_id)
  2. FROM PAINTINGS
  3. GROUP BY painted_by
  4.  
I orginially posted this in the Access forumn but got our sql server 05 db running over the weekend. So, I thought I would post it here since I am still unable to figure it out. This was the query that was suggest from another viewer but I am getting an invalid identifier "b" error message. Thanks for your help in advance.
Expand|Select|Wrap|Line Numbers
  1. SELECT userid as artist,ART_CNT,PAINT_CNT
  2. FROM ARTISTS a
  3. LEFT JOIN
  4. (   SELECT designed_by, Count(art_id) as ART_CNT
  5.     FROM ART 
  6.     GROUP BY designed_by
  7. ) b on a.userid = b.designed_by
  8. LEFT JOIN
  9. (    SELECT painted_by, Count(paint_id) as PAINT_CNT
  10.      FROM PAINTINGS
  11.      GROUP BY painted_by
  12. ) c on a.userid = c.painted_by
Jan 28 '08 #1
1 871
deepuv04
227 Expert 100+
try this query

Expand|Select|Wrap|Line Numbers
  1. SELECT a.userid AS artist, b.ART_CNT, c.PAINT_CNT
  2. FROM   ARTISTS AS a LEFT OUTER JOIN
  3.        (SELECT     designed_by, COUNT(art_id) AS ART_CNT
  4.         FROM          ART
  5.         GROUP BY designed_by) AS b ON a.userid = b.designed_by LEFT OUTER JOIN
  6.       (SELECT     painted_by, COUNT(paint_id) AS PAINT_CNT
  7.         FROM          PAINTINGS
  8.         GROUP BY painted_by) AS c ON a.userid = c.painted_by
Jan 29 '08 #2

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

Similar topics

9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
7
by: Simon Bailey | last post by:
How do you created a query in VB? I have a button on a form that signifies a certain computer in a computer suite. On clicking on this button i would like to create a query searching for all...
4
by: d.p. | last post by:
Hi all, I'm using MS Access 2003. Bare with me on this description....here's the situation: Imagine insurance, and working out premiums for different insured properties. The rates for calculating...
4
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table...
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
5
by: elitecodex | last post by:
Hey everyone. I have this query select * from `TableName` where `SomeIDField` 0 I can open a mysql command prompt and execute this command with no issues. However, Im trying to issue the...
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
4
by: Doris | last post by:
It does not look like my message is posting....if this is a 2nd or 3rd message, please forgive me as I really don't know how this site works. I want to apologize ahead of time for being a novice...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
tracyyun
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...
0
isladogs
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...

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.