Ok, I’m scrapping the old since the code has changed a lot. Here’s what I now have:
SELECT
article.articleId,
article.articleName,
article.articleStoryTypeId,
artIndustry.industryName,
author.userPrefix,
author.userMiddleName,
article.articleStatus,
article.articleCreateDate,
article.articleModifyDate
FROM
users
LEFT JOIN clickTrack
ON users.userId = clickTrack.clickUserId
LEFT JOIN article
ON clickTrack.clickDocumentId = article.articleId
LEFT JOIN users author
ON author.userId = article.articleAuthorId
LEFT JOIN industry artIndustry
ON artIndustry.industryId = substring(article.articleIndustryId,0,charindex(',',article.articleIndustryId)-1)
WHERE ((clickTrack.clickDocumentTable = 'breaking')
OR (clickTrack.clickDocumentTable = 'article'))
AND article.articleCreateDate > '1/1/2008 0:00:00 AM'
AND ((users.userindustryId = '1')
OR (users.userindustryId LIKE '%,1')
OR (users.userindustryId LIKE '%,1,%')
OR (users.userindustryId LIKE '1,%'))
GROUP BY
article.articleId,
article.articleName,
article.articleStoryTypeId,
artIndustry.industryName,
author.userPrefix,
author.userMiddleName,
article.articleStatus,
article.articleCreateDate,
article.articleModifyDate
Order By article.articleId
Data returned looks like:
8332, The Ideal Situation, Breaking News, NULL, NULL, NULL, Prod, 2011-07-25 14:48:01.203, 2011-08-09 07:41:29.373
I added the commas. The 3 null fields are the industry name, user’s first name, and user’s last name. (Yes, someone named the table fields wrong.) I’m extremely tired, so I don’t know if this is enough info or not. Just let me know if you need more.
EDIT
It’s working now. I had to take the “-1” out of the left join on clause. Oh yeah, and I’m just scrapping the name fields. That’s still not working. >.< But I’m done.
Is the author list really the same table as the user list? What are you trying to query for?
One problem is that you are trying to return fields that aren’t in your group by.
Try this: