php - select results from clumon "" and join another table -


client

clientid    userid  customerid 1   1   1 2   2   2 3   3   3 4   4   4 5   5   5 

client service:

    clientserviceid   clientid  serviceid   description      28  10  6           premium master "multaps1.com"      48  134 6           premium master "multaps3.com"      58  135 6           premium master "multaps4.com"      68  137 6           premium master "multaps5.com"          366 273 1           webhosting master "multaps10.com" 

hostingaccount:

    hostingaccountid     domain domainip      username  email     2        multaps1.com         7    bert    bert@in.com     3       multaps2.com         9    bernard     nard.@sedn.ca     4       multaps3.com         3    bree       aenean@cum.org     5       explts.com       1    exploi   ante@cursusluctus.edu     6       multaps5.com    10    rama   quis@tempusrisusuk 

service

serviceid  servicetype 1     1 2     1 3     1 4     2 

i have folowing tables need results this

--------------------------------------------------------------------------- |customerid| description               | domain      | username | email   | --------------------------------------------------------------------------- |  1   | premium master "multaps1.com" | multaps1.com| bert| bert@in.com  | --------------------------------------------------------------------------- |  2   | premium master "multaps2.com" | multaps2.com| bernard| nard@sedn | --------------------------------------------------------------------------- |  2   | premium master "multaps3.com" | multaps3.com| bree   | aan@c.org | --------------------------------------------------------------------------- 

i trying this:

select distinct c.customerid,                                cs.description,                                ha.email,                                ha.domain,                                ha.usernam                            clientservice cs                            inner join client c on c.clientid=cs.clientid                            left join service s                            on cs.serviceid = s.serviceid                            left join hostingaccount ha                            on ha.domain = (select distinct substr(description, locate( '"', description )+1,                                ( char_length( description) - locate('"',reverse(`description`) ) -                                locate('"',description)))                                    clientservice                                    )                                    s.servicetype in (1, 2, 3)                            order ha.hostingaccountid desc 

i keep getting multiple time same domain, username, email , matches other rows this:

---------------------------------------------------------------------------     |customerid| description               | domain      | username | email   |     ---------------------------------------------------------------------------     |  1   | premium master "multaps1.com" | multaps1.com| bert| bert@in.com  |     ---------------------------------------------------------------------------     |  2   | premium master "multaps2.com" | multaps1.com| bert| bert@in.com|     ---------------------------------------------------------------------------     |  2   | premium master "multaps3.com" | multaps1.com| bert   | bert@in.com|     ------------------------------------------------------------------------- 

it other rows to. problem need description between "" , same result domain. way related , cant change tables indexes. don't know how explain appreciated.

your join condition seems overcomplicated. try instead:

left join hostingaccount ha on  cs.description concat('%', ha.domain, '%')  

this return match domain contained within description.

demo here


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -