SQL Exercises: Details of the Prime Ministerial winners after 1972
17. Prime Ministers After 1972
Write a SQL query to display all details of the Prime Ministerial winners after 1972 of Menachem Begin and Yitzhak Rabin.
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
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
-- Filters the rows to only include those where the 'year' column has a value greater than 1972
-- and the 'winner' column has values 'Menachem Begin' or 'Yitzhak Rabin'.
WHERE year > 1972
AND winner IN ('Menachem Begin', 'Yitzhak Rabin');
Output of the Query:
year subject winner country category 1978 Peace Menachem Begin Israel Prime Minister 1994 Peace Yitzhak Rabin Israel Prime Minister
Code Explanation:
The above SQL query retrieves all columns from the 'nobel_win' table where the year of the award is greater than 1972 and the winner's name is either "Menachem Begin" or "Yitzhak Rabin". The query will return all rows that match these criteria, resulting in a list of all Nobel Prizes awarded after 1972 to either Menachem Begin or Yitzhak Rabin. The IN operator allows to check if a value is within a set of values, in this case the query will filter for rows where the winner column is either Menachem Begin or Yitzhak Rabin
Relational Algebra Expression:
Relational Algebra Tree:
Go to:
PREV : Chemistry Winners (1965-1975).
NEXT : Winners with First Name Louis.
Practice Online
For more Practice: Solve these Related Problems:
- Write a SQL query to find all Nobel Prize winners who were presidents after 1980.
- Write a SQL query to retrieve details of Nobel laureates who were prime ministers between 1975 and 1990.
- Write a SQL query to display all winners with the title "Chancellor" after 1970.
- Write a SQL query to list Nobel Peace Prize winners who held political office after 1972.
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.
