1

I want to output all of the IM messages from an OCS database (LcsLogs), for various different users. I want all of the message they send or receive. I have something like the following at the moment:

SELECT * from dbo.Messages where
Messages.FromId = '111' or Messages.ToId = '111' or
Messages.FromId = '222' or Messages.ToId = '222' or
Messages.FromId = '333' or Messages.ToId = '333'

I also want to make absolutley sure I am searching all of the correct tables etc, and being new to LcsLogs databases, I am still not sure if my basic query is comprehensiev enough. I have seen the following query online:

 SELECT * from dbo.Messages, dbo.Users where
 dbo.Users.UserId = Messages.FromId

But I got quite a lot of duplication of messages using this query, and was unsure why we were querying "dbo.Users". Any help with this would be much appreciated.

Kind regards,

greatodensraven
  • 281
  • 1
  • 7
  • 14

1 Answers1

1

You can use this query to get the info that you want:

SELECT * from dbo.Messages where
  Messages.FromId in ('111', '222', '333')
  or
  Messages.ToId in ('111', '222', '333')

or to remove duplicates on your other query, use distinct like this:

SELECT distinct  * from dbo.Messages, dbo.Users where
 dbo.Users.UserId = Messages.FromId
aF.
  • 64,980
  • 43
  • 135
  • 198
  • Thanks, the first query is more relevent i think. Is there any other tables i need to think about? And i also notice alot of the messages contain CSS style parameters, is there any way to remove this effeciently? thanks – greatodensraven Apr 24 '12 at 16:15
  • Put the result that you have now and the result that you intend and I'll answer it better :) – aF. Apr 24 '12 at 16:24