SQLITE在同一个DB中使用SEPARATE TABLE中的NAMES替换列ID

时间:2015-01-10 06:18:47

标签: database sqlite

我在这里有一个sqlite数据库=> https://www.dropbox.com/s/9cn093ns3ot2cik/drinks.db?dl=0

我试图用drinks.glass_id

中的正确名称显示(或替换?)glasses.name

我试过了

select drinks._id DID, 
       drinks.glass_id GID,
       glasses.name GNAME,
       glasses._id GIDD 
from drinks DRNKS
     join glasses GLS
     on drinks.glass_id = glasses._id

有什么不对? 我花了几个小时看这个。 我已阅读这些链接,仍然无法弄明白。

http://community.spiceworks.com/topic/242166-sql-query-help-convert-category-id-to-the-text-name

Replacing a pulled SQL ID value with its name from another table

How to replace fetched values with another column while querying with SQL Server 2008 R2

how to get name from another table with matching id in another table?

1 个答案:

答案 0 :(得分:1)

如果为表指定别名,则必须在任何地方使用

select d._id DID, 
       d.glass_id GID,
       g.name GNAME,
       g._id GIDD 
from drinks d
join glasses g on d.glass_id = g._id