While it would be possible to devise an awkward solution with Calc using VLOOKUP
, this is a typical problem to solve in Base. First, go to File-> New → Database. Hit Next, No, do not register the database and then Finish. Save the file.
Back in Calc, select the data from Sheet 1 column A and drag to the Base window where it says “Tables” to create Table1. For more information on these options, see my answer at https://superuser.com/a/1216718/541756. Do the same for Sheet 2 column B, creating Table2.
Now in the queries section, the first part of your question can be solved by creating the following query in SQL view. (Actually, I created this using Design view, but this way you can copy and paste from the answer).
SELECT "Table1"."VAL" FROM "Table2", "Table1"
WHERE "Table2"."VAL" = "Table1"."VAL"
ORDER BY "Table1"."VAL" ASC
The answer to the second part uses a more complex query, based on sql - How to select all records from one table that do not exist in another table? - Stack Overflow.
SELECT t1."VAL" FROM "Table1" t1
LEFT JOIN "Table2" t2 ON t2."VAL" = t1."VAL"
WHERE t2."VAL" IS NULL
UNION
SELECT t2."VAL" FROM "Table2" t2
LEFT JOIN "Table1" t1 ON t2."VAL" = t1."VAL"
WHERE t1."VAL" IS NULL
Alternatively, use this shorter query for the second part.
SELECT "VAL" FROM (
SELECT "VAL" FROM "Table1"
UNION ALL
SELECT "VAL" FROM "Table2")
GROUP BY "VAL"
HAVING COUNT("VAL") = 1
The results of the queries can optionally be moved back to the Calc spreadsheet by clicking and dragging.
Example files: Untitled 1.ods, New Database.odb