当前位置: 动力学知识库 > 问答 > 编程问答 >

sql server - get all data from two SQL table with a join

问题描述:

I have the query below which creates a join between the two table which is working fint but i would Like to also show all the data which is in "T" that doesnt appear in D. this only Show the Twwet Id which come in both, can I also show the Ones Which dont Apper in D but do in T

SELECT

t.ClientId,

t.PageName,

t.Country,

t.CreatedAt,

t.TweetId,

t.TweetMessage,

t.Replied,

t.RetweetCount,

t.FavoritedCount,

t.en_Media_type,

Sum(d.FollowersCount) As TotalFollowers

FROM dbo.[Tweets(HT)] AS t

INNER JOIN dbo.RetweetersData AS d ON d.TweetID = t.TweetId

WHERE t.ClientId = 54

GROUP BY t.ClientId,

t.PageName,

t.Country,

t.CreatedAt,

t.TweetId,

t.TweetMessage,

t.Replied,

t.RetweetCount,

t.FavoritedCount,

t.en_Media_type

网友答案:

Change

INNER JOIN dbo.RetweetersData ...

to

LEFT JOIN dbo.RetweetersData ...

See this explanation of joins

网友答案:

i think you need to use Left join instead of Inner join try following

SELECT     
  t.ClientId,  
  t.PageName, 
  t.Country, 
  t.CreatedAt,
  t.TweetId,
  t.TweetMessage, 
  t.Replied, 
  t.RetweetCount, 
  t.FavoritedCount, 
  t.en_Media_type, 
  Sum(d.FollowersCount) As TotalFollowers
FROM dbo.[Tweets(HT)] AS t
Left JOIN dbo.RetweetersData AS d ON d.TweetID = t.TweetId
WHERE t.ClientId = 54 
GROUP BY t.ClientId,  
  t.PageName, 
  t.Country, 
  t.CreatedAt,
  t.TweetId,
  t.TweetMessage, 
  t.Replied, 
  t.RetweetCount, 
  t.FavoritedCount, 
  t.en_Media_type
分享给朋友:
您可能感兴趣的文章:
随机阅读: