[eluser]jedd[/eluser]
Hi ricardino,
LEFT JOIN is your friend here.
As an aside, I wrote a guide to [url="http://codeigniter.com/wiki/How_to_ask_a_good_question/"]asking good questions[/url] a while ago - it's always odd to see the actual question (or the question mark) slip in there right at the end of a very long message - means you have to read a really long post all the way through before actually finding out what you're trying to do (in this case a very simple thing) and then re-reading the whole post to make sure the question you asked, the answer I have in my mind, and everything else you've written, all makes sense.
Anyhoo .. your query mentions a thing called
users.userGroup, but your table definition doesn't include any mention of a userGroup. Group implies one to many, which suggests your schema is a bit wonky. This isn't hugely germane to your current problem, but might bite you later.
Quote:Code:
Users:
userId
userName
userAlias
Issues:
issueID
issueClientID
issueOpened
issueClosed
issueAssigned
issueAssignedTo
I'm assuming your multiple WHERE conditions are because you're attempting to qualify your pseudo-joins, and not because you're selecting based on user id - in other words, that you are in fact only trying to select based on an issue ID. Is that right? (Often it's good to describe your question in terms of what you're actually attempting to achieve - your end-game as it were - and not just something like
'I want this in one query?' - which is a touch ambiguous.)
Try something like this:
Code:
SELECT
issueOpened, issueClosed, issueAssigned,
UserReporter.userName,
UserAssigned.userName
FROM
Issues
LEFT JOIN
Users AS UserReporter ON Issues.IssueClientID=Users.UserID
LEFT JOIN
Users AS UserAssigned ON Issues.IssueAssignedTo=Users.UserID
WHERE
Issue.issueID = $issue_id
Untested, of course, so you'll have to play with it - let me know how you go, as I don't have a comparable table set handy here to test it.
Plus your variable naming system is a bit blowy^H^H^H^H^H^Hconfusing - I'd highly recommend you come over to the light side and stick with singular table names, field names that have underscores rather than camel case, remove table names from field names, etc. Ultimately I think consistency is the key here - having
userId and then
issueID - is just plain befuddling. Always write code as though someone else much dumber is going to have to understand it later. (Hint - that someone else will be you, in six months from now.)