w3resource

SQL Exercises: All winners in Physics for 1970 and Economics for 1971


19. Combine Winners (Physics 1970 & Economics 1971)

From the following table, write a SQL query that combines the winners in Physics, 1970 and in Economics, 1971. Return year, subject, winner, country, and category.

Sample table: nobel_win

YEAR SUBJECT                   WINNER                                        COUNTRY                CATEGORY
---- ------------------------- --------------------------------------------- ------------------------- ------------
1970 Physics                   Hannes Alfven                                 Sweden                 Scientist
1970 Physics                   Louis Neel                                    France                 Scientist
1970 Chemistry                 Luis Federico Leloir                          France                 Scientist
1970 Physiology                Ulf von Euler                                 Sweden                 Scientist
1970 Physiology                Bernard Katz                                  Germany                Scientist
1970 Literature                Aleksandr Solzhenitsyn                        Russia                 Linguist
1970 Economics                 Paul Samuelson                                USA                    Economist
1970 Physiology                Julius Axelrod                                USA                    Scientist
.....
1994 Literature                Kenzaburo Oe                                  Japan                  Linguist

View the table

Sample Solution:

-- This query selects all columns from the 'nobel_win' table.
SELECT *
-- Specifies the table from which to retrieve the data (in this case, 'nobel_win').
FROM nobel_win
-- Combines the results of two SELECT statements using the UNION operator.
-- The first SELECT statement retrieves rows where the 'subject' is 'Physics' and the 'year' is 1970.
WHERE (subject = 'Physics' AND year = 1970)
-- The UNION operator combines the results of the first SELECT statement with the results of the second SELECT statement.
UNION
-- The second SELECT statement retrieves rows where the 'subject' is 'Economics' and the 'year' is 1971.
(SELECT * FROM nobel_win WHERE (subject = 'Economics' AND year = 1971));

Output of the Query:

year	subject		winner		country	  category
1970	Physics		Hannes Alfven	Sweden	 Scientist
1970	Physics		Louis Neel	France	 Scientist
1971	Economics	Simon Kuznets	Russia	 Economist

Code Explanation:

The said SQL query retrieves all columns from the 'nobel_win' table and combines them with the results from another query. The first query selects all columns from the table where the subject is 'Physics' and the year is 1970. The second query selects all columns from the table where the subject is 'Economics' and the year is 1971. The UNION operator combines the results of both queries, returning all rows from the first query and the second query that are unique. The output will be a list of all unique nobel prize awarded in 1970 for physics and 1971 for economics.

Relational Algebra Expression:

Relational Algebra Expression: Show all the details of the winners with first name Louis.


Relational Algebra Tree:

Relational Algebra Tree: Show all the details of the winners with first name Louis.


Go to:


PREV : Winners with First Name Louis.
NEXT : 1970 Winners Excluding Physiology & Economics.


Practice Online



For more Practice: Solve these Related Problems:

  • Write a SQL query to combine winners in Chemistry (1965) and Literature (1970).
  • Write a SQL query to merge winners in Physiology (1970) and Peace (1971).
  • Write a SQL query to display winners in Physics (1980) and Economics (1985).
  • Write a SQL query to combine winners in Literature (1990) and Peace (1995).


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.