I’m trying to access a little more info that my current query is giving me.
Here’s the initial query:
SELECT u.uid, u.name, u.mail, n.title AS ‘group’
FROM users u
LEFT JOIN profile_values pv
ON u.uid = pv.uid
LEFT OUTER JOIN og_uid og
ON u.uid = og.uid
LEFT OUTER JOIN node n
ON og.nid = n.nid
WHERE pv.fid = 361 AND pv.value = 114;
In addition, I’m trying to get the values out of the profile_values table for each user where the fid = 41 (the phone# value).
Here’s what the profile_values field looks like:
mysql> describe profile_values;
±------±-----------------+
| Field | Type |
±------±-----------------+
| fid | int(10) unsigned |
| uid | int(10) unsigned |
| value | text |
±------±-----------------+
3 rows in set (0.00 sec)
SELECT u.uid, u.name, u.mail, n.title AS 'group'[color=red], pvphone.value AS `phone`[/color]
FROM users u
LEFT JOIN profile_values pv
ON u.uid = pv.uid
[color=red]LEFT JOIN profile_values pvphone
ON pvphone.uid = u.uid AND pvphone.fid = 41
[/color]LEFT OUTER JOIN og_uid og
ON u.uid = og.uid
LEFT OUTER JOIN node n
ON og.nid = n.nid
WHERE pv.fid = 361 AND pv.value = 114;
I think I may be using the wrong join syntax since I’m getting multiple records for each uid unless I add the DISTINCT limiter.
Am I joining incorrectly? Or is the query, with DISTINCT, correct?
SELECT DISTINCT(u.uid), u.name, u.mail, n.title AS ‘group’
FROM users u
LEFT JOIN profile_values pv
ON u.uid = pv.uid
LEFT OUTER JOIN og_uid og
ON u.uid = og.uid
LEFT OUTER JOIN node n
ON og.nid = n.nid
WHERE n.nid = 1786201
ORDER BY og.created DESC;