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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

join like clause

Status
Not open for further replies.

jvande

MIS
Jun 6, 2001
115
US
I am trying to have a query where it joins two tables where the names are like one another.

select name,school,address,city,st_abbr,zip5,phone
from temp_complete_list c
join temp_sss s on st_abbr=state_code
where name like '%'school'%' ---------This doesn't work

Is it possible to do a query like this?
 
1. Your query joins the two tables on state code, not school name. The where clause is applied after the tables are joined.

2. I can't think of a way to do what you want, except maybe extracting the relavent portion of the name into a separate field so you can use an equality test, or using a CONTAINS test instead of LIKE. I realize these suggestions are long shots.

Lastly, for clarity, you might want to alias your field names so we could tell which fields are in which tables:

select c.name,s.school,c.address,s.city,... etc

Mike Krausnick
Dublin, California
 
Code:
select name,school,address,city,st_abbr,zip5,phone
from temp_complete_list c
join temp_sss s on st_abbr=state_code
and name like '%' + school + '%'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top