SQL ZOO | Sololearn: Learn to code for FREE!

-9

SQL ZOO

Hi, can you please help me with this query? Thank you 1) A new animal has come in, with the following details: name - "Slim", type - "Giraffe", country_id - 1 Add him to the Animals table. 2) You want to make a complete list of the animals for the zoo’s visitors. Write a query to output a new table with each animal's name, type and country fields, sorted by countries.

12/20/2020 7:45:27 PM

Sort Ravn

59 Answers

New Answer

+8

Thank you HBhZ_C I thought that I have to do it one by one. So solution for it is: 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

+10

How do I get the output to uppercase the first letter of each output?

+7

But your code is not complete you have to use inner join to display the table as they give in the test cases order by country ....

+4

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;

+4

Souhaïla Bouras You didn't put semicolon after VALUES('Slim', 'Giraffe', 1)

+3

yes, but it is the last task and I cant find anything wrong with my query INSERT INTO Animals (name, type, country_id) VALUES ('Slim', 'Giraffe', 1); that is for the task 1) and I cant see the mistake

+3

Same problems with lowercase/uppercase!((

+3

This is what I used and it works! 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;

+2

Muthu kumar.V This is right Code and running perfectly. This will 💯 works 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;

+2

Muthu kumar.V Welcome

+1

insert into Animals values ('Slim', 'Giraffe', 1); select name, type, country from Animals join Countries on Animals.country_id = Countries.id order by country;

+1

I can't get It to work also, i even tried a simple select * from Animals, but It says no output, it's driving me crazy

+1

Thank you Sort Ravn

+1

Also getting the output in lowercase while the intended output is supposed to be in capital letters for all the columns except the titles. The code: 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;

+1

Muthu kumar.V Wait

+1

+1

mariem khelifi I had checked it it's working perfectly.

+1

I followed the instruction and used INSERT and INNER JOIN. I only had to order the by country id. /* First insert the new animal into Animals Table*/ INSERT INTO Animals(name,type,country_id) VALUES ('Slim', 'Giraffe', 1 ); /* Join the table Animals and Countries and order by country_id*/ SELECT animals.name, animals.type, countries.country From Animals INNER JOIN Countries ON country_id = id order by country_id desc; Hope this helps :)

0

Glad to see that you found the solution by your single effort and gain SQL certif.congrat.

0

it seems you must write all the queries for both parts first.