• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

grabbing same column information from 5 tables

I have the following tables: Category, CategoryBeauty, CategoryMovies, CategoryMusic, CategorySports

- Each table have the same columns: CategoryID, Name
- Some of the tables have the same Name field, but with diferent CategoryID's.  (e.g News is in Category and CategoryMovies)

I would like a stored procedure to grab DISTINCT Name from all 5 tables.

thanks in advance.
0
attipa
Asked:
attipa
1 Solution
 
Patrick MatthewsCommented:
Hello attipa,

SELECT [Name] FROM Category
UNION
SELECT [Name] FROM CategoryBeauty
UNION
SELECT [Name] FROM CategoryMovies
UNION
SELECT [Name] FROM CategoryMusic
UNION
SELECT [Name] FROM CategorySports



Regards,

Patrick
0
 
JimBrandleyCommented:
How about:
Select DISTINCT(name)
FROM
( SELECT name FROM Category
  UNION
  SELECT name FROM CategoryBeauty
  UNION
  SELECT name FROM CategoryMovies
  UNION
  SELECT name FROM CategoryMusic
  UNION
  SELECT name FROM CategorySports)

Jim

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now