- 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.
70 Respostas
- 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
+ 7
How do I get the output to uppercase the first letter of each output?
+ 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 ....
+ 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
+ 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
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
Same problems with lowercase/uppercase!((
+ 1
Muthu kumar.V
Welcome
+ 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 :)
+ 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
+ 1
Hunter Johnson does the code works !
+ 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
+ 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
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.
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;
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;
0
select animals.name, animals.type, countries.country
from animals inner join countries
on animals.country_id=countries.id
order by countries.country;
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.
0
remove ...FROM Animals,Countries... table Countries cuz you joining it to Animals. Rest of query is correct