M
mr_doles
I have four tables: book_inventory, cd_inventory, movie_inventory, and
lu_location with a relationship on location/purchase_location fields.
I want to create a query for a report that pulls back a count of each
type from a location (i.e. 3 books, 1 movie, 2 CDs from library; 0
books, 2 movies, 5 CDs from Pawn Shop, etc...)
Using a LEFT JOIN gives me incorrect info and INNER JOIN gives me no
info (due to small sample data). This is only step 1 as I want to also
add a WHERE clause using prices and dates. Below is what I am using
now.
SELECT lu_location.location, Count(book_inventory.pk_book_id) AS Books,
Count(cd_inventory.pk_cd_id) AS CDs, Count(movie_inventory.pk_movie_id)
AS Movies
FROM ((lu_location LEFT JOIN book_inventory ON lu_location.location =
book_inventory.purchase_location) LEFT JOIN cd_inventory ON
lu_location.location = cd_inventory.purchase_location) LEFT JOIN
movie_inventory ON lu_location.location =
movie_inventory.purchase_location
GROUP BY lu_location.location
ORDER BY lu_location.location;
I guess a subquery would be the way to go but I can't figure out that
either. Can this even be done. I could also use subreports but it
does not look as clean.
lu_location with a relationship on location/purchase_location fields.
I want to create a query for a report that pulls back a count of each
type from a location (i.e. 3 books, 1 movie, 2 CDs from library; 0
books, 2 movies, 5 CDs from Pawn Shop, etc...)
Using a LEFT JOIN gives me incorrect info and INNER JOIN gives me no
info (due to small sample data). This is only step 1 as I want to also
add a WHERE clause using prices and dates. Below is what I am using
now.
SELECT lu_location.location, Count(book_inventory.pk_book_id) AS Books,
Count(cd_inventory.pk_cd_id) AS CDs, Count(movie_inventory.pk_movie_id)
AS Movies
FROM ((lu_location LEFT JOIN book_inventory ON lu_location.location =
book_inventory.purchase_location) LEFT JOIN cd_inventory ON
lu_location.location = cd_inventory.purchase_location) LEFT JOIN
movie_inventory ON lu_location.location =
movie_inventory.purchase_location
GROUP BY lu_location.location
ORDER BY lu_location.location;
I guess a subquery would be the way to go but I can't figure out that
either. Can this even be done. I could also use subreports but it
does not look as clean.