+ 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 ;
3 Antworten
+ 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;
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?
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;