Tuesday, December 8, 2009

Useful queries.

Aside from the usual select/update/insert/select all
these queries will help you "connect" -or- "relate" your data.


this query will return a table of tweetid/tweet/datestamp/userid/username/userimage:

SELECT dbo.Tweets.TweetID, dbo.Tweets.Tweet, dbo.Tweets.DateStamp, dbo.Users.UserID, bo.Users.UserName, dbo.Users.UserImage
FROM dbo.Tweets INNER JOIN
dbo.Users ON dbo.Tweets.UserID = dbo.Users.UserID

Adding a "WHERE" Clause will allow you to select Tweets on a specific user, or just to get a specific tweet.


this query will return a table of tweetID/tweet/datestamp/keywordid/keyword:

SELECT dbo.Tweets.Tweet, dbo.Tweets.DateStamp, dbo.Keywords.Keyword, dbo.Tweets.TweetID, dbo.Keywords.KeywordID
FROM dbo.Tweets INNER JOIN
dbo.Link ON dbo.Tweets.TweetID = dbo.Link.TweetID INNER JOIN
dbo.Keywords ON dbo.Link.KeywordID = dbo.Keywords.KeywordID

adding a "WHERE" Clause will allow to to select Tweets on a given keyword or keywordID or select all the keywords a specific TweetID


this query will return a table of userid/username/userimages/user_1id/user_1name/user_1images

SELECT dbo.Users.UserID, dbo.Users.UserName, dbo.Users.UserImage, Users_1.UserID AS Expr1, Users_1.UserName AS Expr2,
Users_1.UserImage AS Expr3
FROM dbo.Users INNER JOIN
dbo.Following ON dbo.Users.UserID = dbo.Following.UserID INNER JOIN
dbo.Users Users_1 ON dbo.Following.FollowingUserID = Users_1.UserID

adding a "WHERE" clause, will give you a list of "users_1"s , which is the users a specific "userid" is following are "following"

No comments:

Post a Comment