简体   繁体   中英

Universal searchbox in vb.net & checking from multiple tables

My concept is little unclear. For my site I want to create a searchbox. And I will use Autocomplete function to check related keywords from database. So while typing matching word will come as suggestion. But I am not sure about how to check it through multiple tables. My concept is on health based site so there is different table for each sections like hospitals, doctors, laboratories, chemist etc. I just need guidance how should I do it?

You can use union queries to return autocomplete data for your textbox. For example, you could write a query that for a search term could do this:

select hospitals.name as name
from hospitals
where hospitals.name like '%?%'
UNION
select doctors.lastname as name
from doctors
where doctors.lastname like '%?%'
UNION
select laboratories.labname as name
from laboratories
where laboratories.labname like '%?%'
UNION
...

Be careful though: the performance of this could degrade fast, especially for "contains" searches like the example above ( like '%?%' ).
A faster query would be a "starts with" which would change the like clause in the query above to like '?%'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM