
Shop_id in the shops table relates to numerous records of the employees table: The following diagram shows how each unique That field must belong to the parent table because the primary Largely determined by the role of the shop_id column of the shops table. In fact, the type of relationship that is shared by the two tables is That is to say thatĪ shop_id from the shops table may appear multiple times in the employees TheyĪlso possess what is called a “one-to-many” relationship. Shops and employees tables have a parent/child relationship in that theĮmployees table depends on the values that are stored in the shops table. Thus, the shop_id field appears in both theĮmployees and shops tables because both columns refer to the same data. Establishing TableĬommon practice to assign the same name to fields involved in table joins toīetter demonstrate a relationship. Moment, but first, I’d like to provide some background as to why tables We need a way to tell the database which field we want. Happens because the shop_id field appears in both the target tables. MySQL>SQL Error: Column 'shop_id' in field list is ambiguous. > WHERE employees.shop_id = shops.shop_id *!40000 ALTER TABLE "shops" ENABLE KEYS */Įver executed a query, only to receive the following error? *!40000 ALTER TABLE "shops" DISABLE KEYS */ "shop_id" int(11) NOT NULL AUTO_INCREMENT, *!40000 ALTER TABLE "employees" ENABLE KEYS */ĬREATE TABLE /*!32312 IF NOT EXISTS*/ "shops" ( VALUES (2,1,'f','Barbara Breitenmoser',NULL) INSERT INTO "employees" ("id", "shop_id", "gender", "name", "salary") *!40000 ALTER TABLE "employees" DISABLE KEYS */ Have this table data if you’ve read any of my recent articles.ĬREATE TABLE /*!32312 IF NOT EXISTS*/ "employees" (

Populate two tables named employees and shops. You can’t try your hand at SELECT queries without some data. You just might find that there are a few things you don’t know on Think that this is basic stuff? You might be right, but don’t be too quick That we will look at today are used to disambiguate between duplicate column To minimize headaches that can accompany long field lists,ĭatabase administrators employ a range of techniques. Involving multiple tables, there’s often more to column selection than listing You just might find that there are a few things you don’t know on this subject. Don’t be too quick to judge this as basic stuff. The specific techniques covered today are used to disambiguate between duplicate column names. To minimize headaches that can accompany long field lists, DBAs employ a range of techniques.
