简体   繁体   中英

How to apply searching on two table using mysql

Hi i have two table one is parentlist and childlist.

I have have to apply searching on this table by parentname and childname. I have provided my table structure for better understanding, I have to apply searching on two different field of with different field name.

Fieldname is name in parentlist table and childname in childlist table.

I want below output if I type va then parentlist and childlist record should come in that query like below example. With this va Srting i have a parentname varu123 and childname varu123 so I want these two record after executing the query.

This is the name of First table with fieldname

parentlist

............................................................
 id      name      mobilenumber  user_jid        email
............................................................
 1      varu123     123456         abc21        abc@gmail.com

 2      abhishesk   123456         abc21        def@gmail.com

 3      harsh        1234          def22        123@gmail.com

This is the name of Second table with fieldname

 childlist

..........................................
id user_id    childname     Shoolname  
...........................................
 1    1        ram            St.paul
 2    1        raj            St.xavier
 3    2        varu123        St.paul
 4    2        arun           St.xavier
 5    3        kapil          St.paul
 6    3        kamal          St.xavier

I want this output: .

........................................................................................................
     id      name      mobilenumber  user_jid        email            childname        Shoolname
    ..........................................................................................................
     1      varu123     123456         abc21        abc@gmail.com       ram,raj         St.paul,St.xavier

     2      abhishesk   123456        abc21        def@gmail.com        varu123,arun    St.paul,St.xavier
select pl.*, GROUP_CONCAT(cl.childname), GROUP_CONCAT(cl.Shoolname)
from parentlist as pl
inner join childlist as cl on pl.id=cl.user_id
where pl.name like '%va%' or cl.childname like '%va%'

use MySQL inner join or where :-

select * from parentlist inner join 
childlist on parentlist.id=childlist.user_id 
where childname='varu123' or parentlist.name='varu123'

use MySQL inner join or like :-

select * from parentlist inner join 
childlist on parentlist.id=childlist.user_id 
where childname like '%varu123%' or parentlist.name like '%varu123%'

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