MySQL select from 2 tables without having "shared" key -


searched site , found similar questions, none of solutions worked in case.

i have 2 tables - clients , memberships.

the structure following:

clients client_id other_fields...  memberships membership_id client_id other_fields... 

the field submitted form "membership_id". let's submitted value 5. want use single query select fields memberships , clients

clients.client_id=memberships.client_id , memberships.membership_id!=5

(select other memberships except submitted one). need select records of client has membership_id 5 (records of other clients , memberships should not selected)

used select memberships.*, clients.* memberships memberships, clients clients memberships.client_id=clients.client_id , memberships.membership_id!=5 query displays memberships of clients. , need have memberships of client has membership_id 5.

the problem don't know original client_id, can't include in query

try adding following end:

and exists(select * memberships m             m.membership_id = 5 , m.client_id = clients.client_id ) 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -