简体   繁体   中英

Ambiguous Column Name: SQLite

CREATE TABLE plants (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
  plant_id TEXT NOT NULL UNIQUE,
  plant_name TEXT NOT NULL,
  genus TEXT NOT NULL,
  description TEXT NOT NULL,
  plant_type TEXT NOT NULL,
  file_name TEXT NOT NULL,
  file_ext TEXT NOT NULL
);


INSERT INTO
  plants (id, plant_id, plant_name, genus, description, plant_type, file_name,  file_ext)
VALUES
  (1,'GA_13', 'Pink Muhly Grass', 'Muhlenbergia capillaris', "Muhly Grass is a perennial that takes full sun", "grass",'1.jpg', 'jpg'),
  (2, 'GA_01','Feather reed grass', 'Calamagrostis x acutiflora', "Feather reed grass is a perennial that takes full sun", 'grass','2.jpg', 'jpg'),
  (3, 'SH_32','Smooth Shadbush', 'Amelanchier laevis', "The shadbush is a perennial that can take full sun or partial shade", 'shrub','3.jpg', 'jpg'),
  (4, 'TR_29','Chestnut Oak', 'Quercus montana', "The chestnut oak is a perennial that takes full sun", 'tree','4.jpg', 'jpg'),
  (5, 'GA_20','Sideoats Grama', 'Bouteloua curtipendula', 'Sideoats Grama is a perennial that takes full sun', 'grass','5.jpg', 'jpg'),
  (6, 'GR_14','Feverfew', 'Tanasetum parthenium', "Tanacetum partheniumis a perennial that takes full sun", 'groundcover','6.jpg', 'jpg'),
  (7, 'GA_02','Prairie Cord Grass', 'Spartina pectinata', "Spartina pectinata is not a perennial but takes partial shade or full sun",'grass', '7.jpg', 'jpg'),
  (8, 'FE_01','Christmas Fern', 'Polystichum acrostichoides', "Polystichum acrostichoides is a perennial that prefers full or partial shade", 'fern','8.jpg', 'jpg'),
  (9, 'VI_15','Climbing Hydrangea', 'Hydrangea anomala', "Hydrangea petiolaris is a perennial that prefers full or partial shade", 'vine','9.jpg', 'jpg'),
  (10,'FL_03', 'New England Aster', 'Aster novae angliae', "Symphyotrichum novae-angliae is a perennial that prefers either full sun or partial shade", 'flower','10.jpg', 'jpg'),
  (11,'SH_34', 'Nannyberry', 'Viburnum lentago', "Viburnum lentago, the nannyberry, is a perennial that prefers either full sun or partial shade", 'shrub','11.jpg', 'jpg'),
  (12,'FL_30', 'Hyssop', 'Hyssopus officinalis', "Hyssopus officinalis or hyssop is a perennial shrub that prefers either full sun or partial shade", 'flower','12.jpg', 'jpg');

CREATE TABLE play_types (

  top_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
  plant_id INTEGER NOT NULL,
  playtype TEXT NOT NULL,
  FOREIGN KEY(plant_id) REFERENCES plants(id)

  );

INSERT INTO play_types (top_id,plant_id, playtype)
VALUES
(1, 1,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(2, 2,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(3, 3,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(4, 4,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(5, 5,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(6, 6,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(7, 7,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(8, 8,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(9, 9,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(10, 10,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(11, 11,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio"),
(12, 12,"edible scent sound tactile visual exploratory sensory constructive physical imaginative restorative rules bio");

These are my tables

and I'm merely trying to perform a LEFT JOIN

SELECT play_types.playtype
FROM play_types
LEFT JOIN play_types
ON plants.id = play_types.plant_id;

and i get an ambiguous column name error. How much more different do I need to make things?

you have to use aliases when usig the same table twice

SELECT p1.playtype FROM play_types As p1 LEFT JOIN play_types p2 ON p1.id = p2.plant_id;

But i think you want

SELECT play_types.playtype
FROM play_types
LEFT JOIN plants
ON plants.id = play_types.plant_id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM