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,

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top