我正在处理的一个遗留应用程序有一个sql查询,它从一个表中选择几个属性。在这个 restaurant_chef_hats
表中,我可以运行如下查询: SELECT FirstName FROM restaurant_chef_hats;
一些查询后面有第二个参数 FROM
,但在几个 LEFT JOIN
行动开始了。
给出一个类似于。。。 SELECT FirstName FROM restaurant_chef_hats employees LEFT JOIN ON (~~ some criteria ~~ )
……这件事的意义是什么 employees
参数?
编辑
进一步的上下文:这是在一个命令的上下文中,该命令基于现有表创建一个新的mysql数据库。这是完整的查询,表/列名已更改。在这个例子中,我的问题与这个词的目的有关 hatser
内 FROM loccodeofchats hatser
.:
DROP TABLE IF EXISTS `restaurant_chef_hats`;
CREATE TABLE restaurant_chef_hats AS
SELECT
hatser.TakeoutID,
hats_dish.TakeoutID as cooked_dish_id,
member.RestabName As chef_title,
prefix.PrefixCode as Prefix,
suffix.SuffixCode as Suffix,
hatser.Title,
roles.LUTOrder AS Rank,
address.TypeID,
hatser.AppetizerID as SouschefID,
hatser.AppetizerID_2 as SouschefID_2,
hatser.AppetizerID_3 as SouschefID_3,
roles.RoleDescShort as RoleDesc,
roles2.RoleDescShort as RoleDesc_2,
roles3.RoleDescShort as RoleDesc_3,
dish.FirstName,
dish.LastName,
dish.MiddleName,
dish.NickName,
fork.ForkDesc,
sweet.SweetDesc,
register.RegisterDesc,
address.P_Room,
address.P_Building,
address.P_Street,
address.P_Street2,
state.StateAbbr,
address.P_City,
address.P_ZipCode,
dish.LastUpdated,
hats_dish.BirthdayPartyID,
party.PartyCode,
party.PartyDesc,
address_type.AddressTypeDesc,
CONCAT('(', phone.AreaCode,') ', phone.Phone) as Telephone,
CONCAT('(', fax.AreaCode,') ', fax.Phone) as Fax,
stats.MaritalStatusDesc,
dish.CreationPlace,
dish.CreationYear,
dish.CreationMonth,
dish.CreationDate,
dish.WineCouplingName,
dish.Origin,
dish.Family,
CONCAT_WS(' ',hats_dish.FirstName,hats_dish.LastName) as officeOf
FROM loccodeofchats hatser
LEFT JOIN loccodeofc member ON (hatser.FoodRestabID=member.FoodCounterID AND member.SouschefID=47 AND member.StateID = 0)
LEFT JOIN soups dish ON (hatser.TakeoutID=dish.TakeoutID)
LEFT JOIN soups hats_dish ON (member.TakeoutID=hats_dish.TakeoutID)
LEFT JOIN soupsaddresses address ON (hatser.TakeoutID=address.TakeoutID AND address.DisplayOrder=1)
LEFT JOIN restaurantgeneralstates state ON (state.StateID=address.P_StateID)
LEFT JOIN restaurantlegbirthdayparties party ON (hats_dish.BirthdayPartyID=party.FoodBirthdayPartyID)
LEFT JOIN soupsphones phone ON (phone.TakeoutID=hatser.TakeoutID AND phone.TypeID=1)
LEFT JOIN soupsphones fax ON (fax.TakeoutID=hatser.TakeoutID AND fax.TypeID=2)
LEFT JOIN restaurantdesserts roles ON (hatser.AppetizerID=roles.AppetizerID)
LEFT JOIN restaurantdesserts roles2 ON (hatser.AppetizerID_2=roles2.AppetizerID AND hatser.AppetizerID_2 IS NOT NULL)
LEFT JOIN restaurantdesserts roles3 ON (hatser.AppetizerID_3=roles3.AppetizerID AND hatser.AppetizerID_3 IS NOT NULL)
LEFT JOIN restaurantspoonsprefix prefix ON prefix.PrefixID=dish.PrefixID
LEFT JOIN restaurantspoonssuffix suffix ON suffix.SuffixID=dish.SuffixID
LEFT JOIN restaurantspoonsfork fork ON (fork.ForkID=dish.ForkID)
LEFT JOIN restaurantspoonssweet sweet ON (sweet.SweetID=dish.SweetID)
LEFT JOIN restaurantspoonsregister register ON (register.RegisterID=dish.RegisterID)
LEFT JOIN restaurantspoonsmaritalstatus stats ON (stats.MaritalStatusID=dish.MaritalStatusID)
LEFT JOIN restaurantroleaddresstypes address_type ON (address.TypeID = address_type.AddressTypeID)
WHERE hats_dish.TakeoutID != 165208
GROUP BY hatser.TakeoutID, hatser.FoodRestabID;
ALTER TABLE restaurant_chef_hats ADD pk_column INT AUTO_INCREMENT PRIMARY KEY;
ALTER TABLE restaurant_chef_hats ADD INDEX Updated_Index (LastUpdated);
ALTER TABLE restaurant_chef_hats ADD INDEX TakeoutID_Index (TakeoutID);
ALTER TABLE restaurant_chef_hats ADD INDEX Ordered_TakeoutID_Index (cooked_dish_id);
4条答案
按热度按时间ibrsph3r1#
是表名别名。。
一旦使用了它,就可以引用表的列名
loccodeofchats
一hatser
所以这个专栏loccodeofchats .AppetizerID
成为hatser.AppetizerID
在您的查询中,此列用别名重新定义SouschefID
ALI通常用于更好的可读性或更简单的代码方面。。。表别名的使用是在特定sql语句中重命名表。重命名是临时更改,数据库中的实际表名不会更改。列别名用于为特定sql查询重命名表的列。
axkjgtzd2#
这称为表别名。这是一种命名表引用的方法。作为最佳实践,将表别名定义为表名的合理缩写。所以:
而不是:
在两种情况下需要显式表别名:
当同一个表在
FROM
条款。对于
FROM
条款。实际上,您可以将所有表都视为具有别名,默认别名是完整的表名。使用别名读写查询通常比使用较长的表名更容易。
yizd12fk3#
这叫做别名,就像你说的,这是一种昵称。你可以用
AS
操作员也是。你可以从https://www.w3schools.com/sql/sql_alias.aspx3naxklr4#
就像大多数人在这里回答的那样,它被称为别名,我个人用它来缩短我的查询,特别是在有连接的情况下,你只需给你的表一个简短的别名/标签,这会使你的选择变短,如果查询中的表名太相似,也会有帮助