Reputation: 13
Problem: There are 2 tables that I know I need to use.
I need to find books, magazines, flyers that have the word "sport" in the title.
Example Table Library1: books, magazines etc,... title
Example Table Library2: flyers, etc (THIS TABLE DOES NOT HAVE title column anywhere)
Psuedocode: Select books, magazines, flyers from BOTH TABLES where title like '%sport%'; I need results for anything matching "sport" and to show if it's a book, magazine or whatever.
Not sure if I need a Left Join, Join, or Outer.
What's the syntax for this?
Upvotes: 0
Views: 59
Reputation: 700182
Neither. You would use a union. Example:
select title, 'book' as product from books where title like '%sport%'
union all
select title, 'magazine' from magazines where title like '%sport%'
union all
select title, 'flyer' from flyers where title like '%sport%'
Upvotes: 3