Why my SQL query is not working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why my SQL query is not working

INSERT INTO Animals VALUES ('Slim','Giraffe',1); CREATE VIEW list AS SELECT name,type,country FROM Animals INNER JOIN Countries ON Animals.country_id=Countries.id ORDER by id; select * from list ;

19th May 2021, 4:24 PM
abdelhamid zerrai
abdelhamid zerrai - avatar
3 Answers
+ 1
abdelhamid zerrai , This is working: /* name - "Slim", type - "Giraffe", country_id - 1 */ Insert into animals (name,type,country_id ) Values ('Slim','Giraffe',1); select animals.name,animals.type , countries.country from animals inner join countries on countries.id = animals.country_id order by Country;
20th May 2021, 5:50 PM
Raj Laxmi Verma
Raj Laxmi Verma - avatar
0
It is not a simple query. ;-) I don't know your database, but let's try it. 1) Use of the ID-s doesn't seem consistent. country_id and id? 2) The 'order by' line unnecessary. 3) do you have a Countries table at all?
19th May 2021, 7:13 PM
dozule
dozule - avatar
0
INSERT INTO Animals (name, type, country_id) VALUES ('Slim', 'Giraffe', 1); SELECT Animals.name, Animals.type, Countries.country FROM Animals INNER JOIN Countries ON Animals.country_id=Countries.id ORDER BY country;
27th May 2021, 1:04 PM
Lucky Junihardi
Lucky Junihardi - avatar