Question

Can someone please help me. I am having trouble writing the following SQL query: "Retrieve the...

Can someone please help me. I am having trouble writing the following SQL query: "Retrieve the name and country of the player with the most yellow cards in the 2014 world cup." The player and country are in the player table, and the yellow cards are in the player_cards table. The tables can be connected on player_id. The problem I am having is that there are 3 players that have 3 yellow cards, not just a single player. (3 yellow cards is the most that any player has in my tables.) Thank you for any help you can give.

edited to add: I can get the query to work if I set the where player_cards = 3, but I need to do it using MAX somehow.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SQL query: "Retrieve the name and country of the player with the most yellow cards in the 2014 world cup."

Player Table (player_id, player_name, country)

Player_cards Table (player_id, yellow_cards)

SELECT
p.player_name, p.country
FROM
player p INNER JOIN player_cards c
ON p.player_id = c.player_id
WHERE c.yellow_cards = (
       SELECT DISTINCT MAX(c1.yellow_cards) FROM
       player p1 INNER JOIN player_cards c1
       ON p1.player_id = c1.player_id
       GROUP BY p1.player_id
   )

*** To select for the game 2014 world cup, you can put condition as game = "2014 world cup" in WHERE clause.

*** Sub-query is used to find the MAX(yellow_cards) from the table and use it in the WHERE clause.

Add a comment
Know the answer?
Add Answer to:
Can someone please help me. I am having trouble writing the following SQL query: "Retrieve the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me in writing a detailed mechanism for the above reaction. I am having trouble...

    Please help me in writing a detailed mechanism for the above reaction. I am having trouble determining if it is an aldol addition. Usually those are with aldehydes as the starting material? Thanks in advance!! O NaOH, H2O b. heat

  • Can someone please help me with this problem? I am having trouble with figuring it out....

    Can someone please help me with this problem? I am having trouble with figuring it out. Thank you in advanced! The 10x objective has a numerical aperture of 0.25. What would be the smallest distance (in μm) between two objects that can be resolved when using that objective with light at 400 nm?

  • SQL: Can someone please help me ASAP?? I need to create QUERIES for 2 INNER JOINS...

    SQL: Can someone please help me ASAP?? I need to create QUERIES for 2 INNER JOINS with 3 or more tables. I have an HR Database with the tables Region, Location, Country, Job, Department, Employee, Dependent. Any help would be greatly appreciated...

  • Can someone help me with these 2, I am having trouble solving them. Question 4 Using...

    Can someone help me with these 2, I am having trouble solving them. Question 4 Using the tables for water determine the specified property data at the indicated state. For H2O at p = 0.7 MPa and v = 0.62 m3/kg, find h in kJ/kg. Note: Round up the answer to 2 decimal places. --------------------------------------------------------------------- Question 5 Using the tables for water determine the specified property data at the indicated state. For H2O at p = 0.7 MPa and v...

  • I am using Oracle SQL Live so please write the SQL Query in the format that...

    I am using Oracle SQL Live so please write the SQL Query in the format that Oracle SQL Live can run I need to create a trigger that will update the Product QoH when a new product is purchased. (A new product is purchased when a row is added to the line table). I have linked the code of the script since it exceed Chegg’s Character Limit: https://docs.google.com/document/d/1HbHnMrk6Qw99B72kpDyYCFibUJVsYEi-6RKDsmb3fg4/edit?usp=sharing

  • I am having trouble writing an evaluation note of my progress in clinical. Mid-semester, i was...

    I am having trouble writing an evaluation note of my progress in clinical. Mid-semester, i was told by the professor i had trouble documenting but that my technique for physical assessment as well as the performance was improving fast. I need to incorporate tasks i have learned such as: a.m. care, oral care, bed bath, bed making, standard precaution, enteral feeding, help with feeding patients, incontinence care. Can you give me a short paragraph on how to write this?

  • Hi, I am having trouble with this question. I'm not sure why it was wrong. Please...

    Hi, I am having trouble with this question. I'm not sure why it was wrong. Please show your work, so I can correct my thinking. I appreciate your help! Problem 3.14 Mendel crossed peas with round, green seeds with peas having wrinkled, yellow seeds. All F1 plants had seeds that were round and yellow Part A Predict the results of testcrossing these F1 plants. O 1/4 round, yellow; 1/4 round, green; 1/4 wrinkled, yellow; 1/4 wrinkled, green O1/2 round, yellow:...

  • I am having trouble with these questions. Can anybody help me please. Given the following correctly...

    I am having trouble with these questions. Can anybody help me please. Given the following correctly BALANCED reaction: PENTANE (72 g/mol) 5. (3 pts) How grams of CO2 are created from 6. (3 pts) How many grams of pentane will be needed t 1440 grams of CsH12 (pentane). c5H12 + 802 → 5CO2 + 6H20 ΔΗ=-840 kcals/mol create 250 kilocalories? (the energy in a candy bar) 7. (2 pts) When 100 moles of pentane (CsH2) are mixed with 20 kilograms...

  • I am having trouble solving these types of problems. Please help me understand by explaining and...

    I am having trouble solving these types of problems. Please help me understand by explaining and showing me the steps and methods needed to work this out. thank you.

  • Can anyone please help me with these SQL Server Questions? I am using SQL Server 2008...

    Can anyone please help me with these SQL Server Questions? I am using SQL Server 2008 1. Write the code to create two table with at least 10 fields of various data types. 2. Write the code to insert 20 rows of data into the table that you created. 3. Write the code – “Select” statements to write three different reports from your data. 4. Write the code to create a report that incorporates functions. 5. Write the code to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT