jackblack
jackblack

Reputation: 1

Is this sql query correct?

Using table below https://i.sstatic.net/Wmg2C.png

How do i display the names of toys that processed by Female Employees who are in level 3, level 4, and level 5 (not level 1 or 2) and a list of all toys’ name with stores’ postcode 10005. Write using union.

SELECT Toy_name
FROM Toy T
INNER  JOIN hire_transaction H on T.toy_id = H.toy_id
INNER  JOIN Employee E on H.E_id = E.E_id
WHERE E_Sex = ‘F’
AND E_Level between ‘3’ and ‘5’
UNION
SELECT Toy_name, Store_id
FROM Toy T, Store S
WHERE T.Store_ID IN(
SELECT Store_ID
FROM STORE S
WHERE Store_Postcode = ‘10005’);

this is my attempt. am i correct?

Upvotes: 0

Views: 31

Answers (1)

Philipp
Philipp

Reputation: 2796

SELECT Toy_name
FROM Toy T
INNER  JOIN hire_transaction H on T.toy_id = H.toy_id
INNER  JOIN Employee E on H.E_id = E.E_id
WHERE E_Sex = 'F'
AND E_Level between 3 and 5
UNION

SELECT Toy_name
FROM Toy T
WHERE T.Store_ID IN(
SELECT Store_ID
FROM STORE S
WHERE Store_Postcode = '10005');

When using unions the distinct selects must have the same number and types of columns.

Removed the unnecessary implicit join in your second query.

You used the wrong quotation marks, inserted the single quotes.

Upvotes: 1

Related Questions