+ 1
Zoo SQL Project challenge
Hi, I’m having difficulties with the last project. I get wrong result every time when I fix it. Can someone help me with the code or fix it? Thanks! /* name - "Slim", type - "Giraffe", country_id - 1 */ INSERT INTO Animals (name, type, country_id) VALUES ('Slim', 'Giraffe', 1); Select name, type, country from animals, countries
20 Respostas
+ 8
Thank you Ipang! I did it! Here’s my solution if you need it!
/* 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, countries
WHERE animals.country_id=countries.id order by animals.country_id desc
+ 4
INSERT INTO Animals (name, type, country_id)
VALUES ('Slim', 'Giraffe', 1);
SELECT name, type, country FROM Animals INNER JOIN Countries ON Animals.country_id = Countries.id ORDER BY country
+ 2
Still showing me an error, for some reason I get the output 3 times
+ 1
You mean output like this?
Slim Giraffe 1
Slim Giraffe 1
Slim Giraffe 1
I would guess there are already some records in the table, all with same values. Probably the records entered in previous INSERT command.
Oh well, good luck with solution then 👍
+ 1
No sweat bro 👌
Anyways, now that you mention another table, I guess you may find a need to use JOIN.
https://www.sololearn.com/learn/SQL/1865/
+ 1
No bro this are all shows error at WHERE which is syntax error this is code code.
Just replace at" FROM animals, countries"
to " FROM Animals INNER JOIN Countries"
And remove WHERE end place "ON" there
Then all set.
INSERT INTO Animals (name,type, country_id) VALUES('Slim', 'Griffe', 1);
SELECT Animals.name, Animals.type, Countries, country FROM Animals INNER JOIN Countries ON Animals.country_id=Countries.id ORDER BY Animals.country_id DESC;
Which run for sure if not please do same changes
Thank you
+ 1
Hii MD SAIF
I DID Try this and it works
First Even I made same mistakes by putting "Where" at the place "ON" at which every time shows error at "WHERE" Then I take my time Step back at once check the " JOIN" functions in this, end realised that is wrong at "WHERE" in which syntax of "INNER JOIN"is something else than try one again and it work.
If it's right than try,if it's wrong than leave it bro.
Thanks you
+ 1
Working one:
/* name - "Slim", type - "Giraffe", country_id - 1 */
INSERT into animals
VALUES ('Slim','Giraffe',1);
SELECT a.name, a.type, c.country
from animals a
INNER JOIN Countries c
on a.country_id=c.id
ORDER by c.country;
0
SELECT name, type, country_id
FROM animals
How is this?
0
When I do with country_id it works but I need with this format (name, type, country) but country is in another table. When I initialize countries table it and do (name, type, country) it outputs the table 3 times. like Slim Giraffe 1, slim giraffe 2, slim giraffe 3.
Thanks for trying anyways bro!
0
So whats the answer?
0
Ipang, gw outputnya udah sesuai kok masih salah ya
0
Hello, this is what worked for me:
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 countries.country ASC;
0
Just Copy and paste the below code, it will complete the use case of zoo SQL problem.
_____________________________
insert into animals values
('Slim','Giraffe',1);
SELECT initcap(a.name) as name, initcap(a.type) as type,
CASE
when a.country_id=3 then initcap('India')
when a.country_id=2 then initcap('Russia')
when a.country_id=1 then upper('USA')
END
AS country
FROM Animals AS a inner join Countries AS c
on a.country_id=c.id
order by c.country Asc;
0
Small hint...worked for me after many failed attempts...
make sure to capitalize first letters of Slim and Giraffe...
0
What answer plz tell me
0
All programs comes failure what problem I don't know,,😭😭need
answers
0
Same here, I can’t pass this challenge even if the code is as you said
0
INSERT INTO Animals
VALUES ('Slim', 'Giraffe', 1);
SELECT Animals.name, Animals.type, Countries.country
FROM Animals INNER JOIN Countries ON Animals.country_id=Countries.id
ORDER BY Animals.country_id DESC;
/*Just copy and paste. 100% fix*/
0
/* name - "Slim", type - "Giraffe", country_id - 1 */
Insert into Animals values ('Slim', 'giraffe', 1);
create view animal_list as
(
select
Animals.name,
Animals.type ,
countries.country
From countries inner join Animals
on animals.country_id = countries.id
);
select * from animal_list order by country
this did not work although it gives same outpout .... can anyone know why ?