为什么我们不能在连接查询中使用select * for specific table?

时间:2017-03-24 06:37:55

标签: android ios mysql sqlite

我想要来自多个表的记录。我的要求是让所有列形成一个表和一些感兴趣的来自不同表的列。

我们可以使用“ select * from table_name ”进行常规提取查询。但这不适用于连接查询,我必须为该表编写所有列名。

那么,有没有办法用*来获取连接查询中的记录?

SELECT Item.ItemId, Item.Item, ItemIndex.CurrentAverageScore, ItemStyle.ItemStyleId, ItemStyle.ItemStyle, Brewery.BreweryId, Brewery.BreweryDescription, (SELECT PersonalRating FROM UserItemJournal WHERE ItemId = ItemIndex.ItemId) As PersonalRating, (SELECT Notes FROM UserItemJournal WHERE ItemId = ItemIndex.ItemId AND PersonalRating IS NOT NULL) As Notes FROM Item, ItemIndex, ItemStyle, Brewery, UserItemJournal WHERE Item.ItemId = ItemIndex.ItemId AND Item.LanguageId = 1 AND ItemStyle.ItemStyleId = ItemIndex.ItemStyleId AND ItemStyle.LanguageId = 1 AND Brewery.BreweryId = ItemIndex.BreweryId AND Brewery.LanguageId = 1 AND UserItemJournal.PersonalRating IS NOT NULL

在上面的查询中,我想要Item Table中的所有列。 我认为*有限制,我们只能用单张表使用*。如果我错了,请纠正我。

由于

1 个答案:

答案 0 :(得分:1)

您可以使用该表名或别名,然后使用dot star(item。*), 和其他表格列一样,带有别名或表名。

SELECT Item.*, ItemIndex.CurrentAverageScore, ItemStyle.ItemStyleId, ItemStyle.ItemStyle, Brewery.BreweryId, Brewery.BreweryDescription, (SELECT PersonalRating FROM UserItemJournal WHERE ItemId = ItemIndex.ItemId) As PersonalRating, (SELECT Notes FROM UserItemJournal WHERE ItemId = ItemIndex.ItemId AND PersonalRating IS NOT NULL) As Notes FROM Item, ItemIndex, ItemStyle, Brewery, UserItemJournal WHERE Item.ItemId = ItemIndex.ItemId AND Item.LanguageId = 1 AND ItemStyle.ItemStyleId = ItemIndex.ItemStyleId AND ItemStyle.LanguageId = 1 AND Brewery.BreweryId = ItemIndex.BreweryId AND Brewery.LanguageId = 1 AND UserItemJournal.PersonalRating IS NOT NULL;