Back to questions
Assume you are given the tables below about Facebook pages and page likes. Write a query to return the page IDs of all the Facebook pages that don't have any likes. The output should be in ascending order.
|20701||Tips for Data Analysts|
Explanation: The page with ID 20701 has no likes.
The dataset you are querying against may have different input & output - this is just an example!
There are two ways to go about it. Either or can be established between tables and or a subquery can be used to identify which pages have not been liked by any user.
The clause starts selecting data from the left table. For each row in the left table (), it compares the value in the column with the value of each row in the column in the right table ().
When page_id are found on both sides, the clause creates a new row that contains columns that appear in the clause and adds this row to the result set.
In case from table is not available in table, the clause also creates a new row that contains columns that appear in the clause. In addition, it fills the columns that come from the (right table) with NULL. Rows having NULL values in the result is the set of the solution.
Read about  and  to get the better understanding.
Solution #1: Using LEFT OUTER JOIN
Another solution to this problem, since pages with NO LIKES are needed, would be the clause (refer to Solution #2). It's an appropriate and efficient operator to get this information. Check out here.
Both methods give the same output.
Solution #2: Using
Solution #3: Using