Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/29/2021 in all areas

  1. Avoid using "global". Instead, pass the $employees array as an argument to functions. EG echo getTotalSalaries($employees); function getTotalSalries($emps) { return array_sum(array_column($emps, 'salary')); }
    1 point
  2. My take on this, is that it makes more sense if you can break it down into problems: 1. What list of actors (actor_id) do you need? You need actors with a name like "depp" AND actors who were in the 'ACE GOLDFINGER film". This 1st query gets you those actors. SELECT actor_id FROM actor WHERE last_name like '%depp%' UNION SELECT actor_id FROM film_actor WHERE film_id = (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER'); To get the full list of films, you need to get all the films for any of those actors, so you have to join your list of actors to the film_actor table, so one very simple way to think about this, is to use some subqueries fed into the upper query. The original query, can be used as a subquery to get you the list of actors. SELECT DISTINCT f.film_id, f.title FROM film f JOIN film_actor fa ON f.film_id = fa.film_id WHERE fa.actor_id IN (SELECT actor_id FROM actor WHERE last_name LIKE '%depp%' UNION SELECT actor_id FROM film_actor WHERE film_id = (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER') ) ORDER BY f.title; Here's another syntactical take, joining to the subquery rather than using IN SELECT DISTINCT f.film_id, f.title FROM film f JOIN film_actor fa ON f.film_id = fa.film_id JOIN (SELECT actor_id FROM actor WHERE last_name LIKE '%depp%' UNION SELECT actor_id FROM film_actor WHERE film_id = (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER') ) as a ON fa.actor_id = a.actor_id ORDER BY f.title; And here's a version, where the 'ACE GOLDFINGER' query is also a join to a subquery. This one is probably a bit more correct, in the case that there was more than one 'ACE GOLDFINGER" titled film, that might have different actors. SELECT DISTINCT f.film_id, f.title FROM film f JOIN film_actor fa ON f.film_id = fa.film_id JOIN (SELECT actor_id FROM actor WHERE last_name LIKE '%depp%' UNION SELECT actor_id FROM film_actor JOIN (SELECT film_id FROM film WHERE title = 'ACE GOLDFINGER' ) as ace ON film_actor.film_id = ace.film_id ) as a ON fa.actor_id = a.actor_id ORDER BY f.title;
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.