Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Multiple Tables 1

Status
Not open for further replies.

Tambourine

Programmer
Oct 9, 2006
4
GB
I have a database called 'xxx', i need to query 3 tables inside this database called a, b, and c. Each table has a common field called artist: i need to select artist from all 3 tables (a, b and c) and group the results by artist. It has a catch of i needs them all to comply with a LIKE statement like below. So far i have:

SELECT a.artist, b.artist, c.artist FROM a, b, c WHERE a.artist, b.artist, c.artist LIKE '$_GET%' GROUP BY a.artist, b.artist, c.a...on how it does work? Any help will be great.
 
SELECT a.artist, b.artist, c.artist FROM a, b, c WHERE a.artist, b.artist, c.artist LIKE '$_GET%' GROUP BY a.artist, b.artist, c.a...st be shutdown to prevent damage to Unknown.
 
That solution is along the lines... i thought that is what i wanted but... i want it to display all artist then if there is a duplicate artist from either, it will only display it once, instead of the amount of times it appears in a table.

My explaining is poor.

Example say i had these artist in table a:

ttt
fff
hhh

Example say i had these artist in table b:

ttt
fff
ddd

Example say i had these artist in table c:

ttt
fff
kkk

then i would want my results to be:

ttt
fff
ddd
kkk

Hope this helps you understand what im looking for a little better :)
 
Code:
select artist
  from [b]a[/b]
 where artist like '$_GET[url]%' 
union
select artist
  from [b]b[/b]
 where artist like '$_GET[url]%' 
union
select artist
  from [b]c[/b]
 where artist like '$_GET[url]%' 
order 
    by artist

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top