I have a table like this :
id firstname lastname cilinic1 cilinic2 ... insurance1 insurance2
1 rose golabi bla bla bla bla firaga atena
*2 ... ... ... ... filoli* filoli*
3 ... ... ... ... tomis atena
.
.
.
When user tries to search for a specific insurance like (atena) , I make a query like this:
SELECT * FROM doctors WHERE insurance1 LIKE ($userinput) ..
But this query will search just in insurance1
The problem is , some doctors have 2 different clinics , and in each clinic maybe accept the same insurance (Like the row number 2 from this table , which I emphesized with * ) .
So , I have to search in both insurance1 ANd insurance2 simultaneously , and if a doctor accepts same insurance in 2 clinic , I want to show that doctor twice in the search result
what should I do ?
(NOTE: I have to select * , because there are 12 columns in my table and I have to show everything in the search result(firstname,lastname,age,gender,city,....))
Is There a way to say this sentence to mysql :
if you selected from **insurance1** then (function...)
if you selected from **insurance2** then (function...)
????
You can use UNION
to combine two separate queries:
SELECT * FROM doctors WHERE insurance1 LIKE ($userinput) ..
UNION ALL
SELECT * FROM doctors WHERE insurance2 LIKE ($userinput) ..
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.