- 14

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.

20th Dec 2020, 7:45 PM
Sort Ravn
Sort Ravn - avatar
70 Réponses
- 16
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
20th Dec 2020, 11:40 PM
Sort Ravn
Sort Ravn - avatar
+ 7
How do I get the output to uppercase the first letter of each output?
30th Apr 2021, 12:07 PM
Gregory Dappert
Gregory Dappert - avatar
+ 3
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 ....
20th Dec 2020, 11:22 PM
HBhZ_C
HBhZ_C - avatar
+ 1
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
20th Dec 2020, 8:11 PM
Sort Ravn
Sort Ravn - avatar
+ 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
13th Feb 2021, 5:52 PM
Henry Fantacussi
Henry Fantacussi - avatar
+ 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;
1st May 2021, 1:25 AM
Dar Ko
+ 1
Same problems with lowercase/uppercase!((
1st May 2021, 2:37 PM
Alexey V.
Alexey V. - avatar
+ 1
5th May 2021, 6:24 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
+ 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 :)
26th Jun 2021, 9:33 AM
Niklas Hoffmann
+ 1
How I was taught and get the same answer(The way SoloLearn teaches it is below this) INSERT INTO Animals(name, type, country_id) VALUES ('Slim', 'Giraffe', 1); SELECT name, type, country FROM Animals INNER JOIN Countries ON country_id = id ORDER BY country; This is another "correct answer" but to me it is wrong compared to what the question asked. Also you do not have to do tableA.colmn_name if the column name is in one table. (SoloLEarn taught two different ways, I DO NOT like this way) 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
30th Aug 2021, 4:49 AM
Jacque Trahan
Jacque Trahan - avatar
+ 1
Hunter Johnson does the code works !
8th Feb 2022, 11:48 AM
Tem Dirane Dem
Tem Dirane Dem - avatar
+ 1
insert into Animals values ('Slim', 'Giraffe', 1); select name, type, country from Animals inner join Countries on Animals.country_id = Countries.id order by country
18th Apr 2022, 8:51 PM
Liza Belova
Liza Belova - avatar
+ 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 Animals.country_id=Countries.id order by Countries.country
14th Dec 2022, 11:03 PM
Samba Sy
Samba Sy - avatar
0
Glad to see that you found the solution by your single effort and gain SQL certif.congrat.
20th Dec 2020, 11:45 PM
HBhZ_C
HBhZ_C - avatar
0
it seems you must write all the queries for both parts first.
7th Jan 2021, 6:58 AM
Danny Wanyoike
Danny Wanyoike - avatar
0
insert into Animals values ('Slim', 'Giraffe', 1); select name, type, country from Animals join Countries on Animals.country_id = Countries.id order by country;
4th Feb 2021, 12:13 PM
Chandra Kant
Chandra Kant - avatar
0
/* name - "Slim", type - "Giraffe", country_id - 1 */ 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 country;
11th Feb 2021, 4:06 AM
mohammad sadegh davodvandi
mohammad sadegh davodvandi - avatar
0
select animals.name, animals.type, countries.country from animals inner join countries on animals.country_id=countries.id order by countries.country;
13th Feb 2021, 5:53 PM
Henry Fantacussi
Henry Fantacussi - avatar
0
INSERT INTO Animals VALUES ('Slim','Giraffe',1); SELECT Animals.name,Animals.type,Countries.country FROM Animals,Countries INNER JOIN Countries ON Animals.country_id=Countries.id ORDER BY Countries.country; Not working.
17th Feb 2021, 9:26 AM
Md Imraj Hossain
Md Imraj Hossain - avatar
0
remove ...FROM Animals,Countries... table Countries cuz you joining it to Animals. Rest of query is correct
19th Feb 2021, 12:50 PM
Артём Сильченко
Артём Сильченко - avatar