runtime
105 / 139

task UNION / INTERSECT / EXCEPT · medium

Predict: duplicate values in a set

Predict both counts for the fuel lists of two authorities on one day.

what to return

Columns
union_rowsunion_all_rows in this order
Rows
in the order asked
Watch for
Use only the sample rows shown. NULL is not zero or empty text. Keep duplicate rows.
Skill
Reason about the exact result of a fixed SQL query. Refresher: Combine sets with UNION →

data you can query

Energy dataset: the first 6 rows of each table. Under each column name: the kind of value it holds, and which table it links to. Your queries run on all rows.

fuel_sample2 columns · 16 rows
ba_codefuel_code
ISNECOL
ISNENG
ISNENUC
ISNEOIL
ISNEOTH
ISNESUN
ba_code
ISNE
fuel_code
COL
ba_code
ISNE
fuel_code
NG
ba_code
ISNE
fuel_code
NUC
ba_code
ISNE
fuel_code
OIL
ba_code
ISNE
fuel_code
OTH
ba_code
ISNE
fuel_code
SUN

first 6 of 16 rows · your queries use all of them

predict.sql
SELECT
  (
    SELECT COUNT(*)
    FROM (
      SELECT fuel_code
      FROM fuel_sample
      WHERE ba_code = 'ISNE'
      UNION
      SELECT fuel_code
      FROM fuel_sample
      WHERE ba_code = 'NYIS'
    )
  ) AS union_rows,
  (
    SELECT COUNT(*)
    FROM (
      SELECT fuel_code
      FROM fuel_sample
      WHERE ba_code = 'ISNE'
      UNION ALL
      SELECT fuel_code
      FROM fuel_sample
      WHERE ba_code = 'NYIS'
    )
  ) AS union_all_rows
Read the query · predict its result
SELECT (SELECT COUNT(*) FROM (SELECT fuel_code FROM fuel_sample WHERE ba_code = 'ISNE' UNION SELECT fuel_code FROM fuel_sample WHERE ba_code = 'NYIS')) AS union_rows, (SELECT COUNT(*) FROM (SELECT fuel_code FROM fuel_sample WHERE ba_code = 'ISNE' UNION ALL SELECT fuel_code FROM fuel_sample WHERE ba_code = 'NYIS')) AS union_all_rows

Look at the sample tables and SQL. Enter the rows you think the query returns, in this column order: union_rows, union_all_rows. Put each row in square brackets, then wrap all rows in another pair of brackets (JSON format). For example, [[1,null]] is one row with 2 values. Replace these with your predicted values. Use numbers without quotes, text in double quotes, and null for SQL NULL. Keep repeated rows. Use [] for no rows. Keep rows in the order specified by ORDER BY.

Hints and the answer are always available. Using them counts the question as solved with help.

Predict: duplicate values in a set — SQL practice · Runtime