简体   繁体   中英

MYSQL query, combine records irrelevant tables for autocomplete

I m trying to create an autocomplete search for my android application. I m using mysql database for this. I want to search three column bu one of the column is on other table. I have 2 table . There are a1 , a2 column in first table and there is username column in second table. I want to search from two table and combine this records for my autocomplete search list. I want to accomplish like this ;

SELECT   *  
FROM     table1 t1, 
         table2 t2 
WHERE    t1.a1  LIKE '%er%' 
OR       t1.a2  LIKE '%er%' 
OR       t2.username LIKE '%er%

I don't want combine related records I want irrelevant records from two tables to one table.

Not : Columns of tables are diffrent from each other.

Please help me about this MYSQL query.

You can't do that like this, while the columns are different. Otherwise UNION would be an idea... I think you have to use multiple queries...

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