1

虽然我查看了互联网上的不同示例,但我无法从多个表中选择数据。我有 2 张桌子。

     1st  has 'logUID', 'groupUID' field.

另一个

    2nd has 'logUID' , 'User ID' , 'LogEntry' , 'LogTypeUID'

我想要完成的是获取 LogUID 相互匹配的日志条目并返回 groupUID 字段,这样我就知道日志针对的是哪个组。当我尝试选择或加入时,我似乎正在重复一个 logUID 字段。

SELECT TOP 10000 [log].[dbo].[Logs].[LogUID], [log].[dbo].[LogGroups].[LogUID],     [Weblog].[dbo].[LogGroups].[GroupUID] 

FROM [log].[dbo].[LogGroups], [log].[dbo].[Logs] INNER JOIN [log].[dbo].[LogGroups] as LG
ON [log].[dbo].[Logs].[LogUID] = LG.LogUID ;

任何帮助。

4

3 回答 3

1

删除额外的 FROM[log].[dbo].[LogGroups],

于 2012-08-14T10:05:17.197 回答
0

[LogGroups]有两次桌子在那里......

  • FROM table1, table2方法table1 CROSS JOIN table2


所以,只需将您的代码更改为以下...

SELECT TOP 10000
  [Logs].[LogUID],
  [LogGroups].[LogUID],
  [LogGroups].[GroupUID]
FROM
  [log].[dbo].[Logs]
INNER JOIN
  [log].[dbo].[LogGroups]
    ON [Logs].[LogUID] = [LogGroups].LogUID ; 
于 2012-08-14T10:06:27.543 回答
-1

See first of all you need to create a relationship between the tables you have created. After creating a relationship you can either create a key relationship using the two columns. So that whatever data goes in the logUID field of first table, the same data goes in the logUID field of second table. So this would help you to fetch the data from both the tables.

Hope this would help.

于 2012-08-14T10:10:48.510 回答