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

Need to search 2 fields in 2 tables 1

Status
Not open for further replies.

blondends

Technical User
Apr 25, 2003
84
GB
Hi,

I can't work out the SQl string needed so that a user input string can be searched for from 2 fields in 2 tables.

I am using LIKE %userinput% to search the fields, this works for one field from one table but i can't get the SQL right for any more than that.

Thanks in advance,

Chris
 
Cool cheers for the quick reply, that sorts out the two fields in the same table but i am still stuck with searching at the same time 2 fields in another table for the same thing. Any ideas ??
 
If you are returning a compatible result set from both tables, you could use a union query

Code:
select c1,c2 from t1
where c1 like '%userinput%'
union
select c3,c4 from t2
where c3 like '%userinput%'

 
I'm sure all you need to do is

SELECT *
FROM table_a a, table_b b
a.c1 LIKE '%userinput%' or b.c2 like '%userinput%'

Have I read your question right?

Jo
 
Ahhhh i see now, i have to use those JOINS like UNION and LEFT and INNER. That now rings a bell !!!! So to get the data from T1 and T2 when either T1 = %var% or T2 = %var% i should use the LEFT JOIN. Thank you soooo much for kick starting my brain !!!

Chris

Star for you !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top