我正在使用的旧版应用程序具有一个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);
是表名的别名..
FROM loccodeofchats hatser
使用完后,您可以引用表loccodeofchats
的列名hatser
所以专栏loccodeofchats .AppetizerID
变成了hatser.AppetizerID
在您的查询中,此列使用别名重新定义,SouschefID
而alis通常用于更好的可读性或更简单的代码方面。
表别名的使用是在特定的SQL语句中重命名表。重命名是一个临时更改,数据库中的实际表名不会更改。列别名用于重命名表的列,以用于特定的SQL查询。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句