post
poster: Thetawaves
description: SQL query
language: plain text
[download]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
SELECT Contacts.*,Accounts.name as aname,Sites.name as sname FROM Contacts,Accounts,Sites WHERE 
(
 (
   Accounts.maincontact = Contacts.cid
   OR
   Accounts.members REGEXP CONCAT('^',Contacts.cid,',')
   OR
   Accounts.members REGEXP CONCAT(',',Contacts.cid,',')
 )
 OR
 (
   Sites.maincontact = Contacts.cid
   OR
   Sites.members REGEXP CONCAT('^',Contacts.cid,',')
   OR
   Sites.members REGEXP CONCAT(',',Contacts.cid,',')
 )
) AND Contacts.cid = 5;