0

I am currently doing pset7 and I have found most of the clues of who it is but the problem is that I need to use the intersect sql function to find the common name of the thief but I am not sure how.

when I put the interest code and try to check for the intersection between all the statements. the terminal says "near "INTERSECT": syntax error"

I am not sure why I am a still a bit confused about sql and some of the commands if anyone could help that would be great

SELECT name FROM people JOIN courthouse_security_logs ON people.license_plate = courthouse_security_logs.license_plate WHERE year = "2020" AND day = "28" AND month = "7" AND hour = "10" AND minute >= "15" AND minute < "25" AND activity = "exit";
INTERSECT
SELECT name FROM people JOIN bank_accounts ON people.id = bank_accounts.person_id JOIN atm_transactions ON bank_accounts.account_number = atm_transactions.account_number WHERE day = 28 AND month=7 AND atm_location="Fifer Street" AND transaction_type = "withdraw" ORDER BY name;
INTERSECT
SELECT name FROM people JOIN phone_calls ON people.phone_number = phone_calls.caller WHERE duration <= 60 AND day = 28 AND month = 7 AND year = 2020 ORDER BY name;
INTERSECT
SELECT name FROM people JOIN passengers ON people.passport_number = passengers.passport_number WHERE flight_id = ( SELECT id FROM flights WHERE month = 7 AND day = 29 AND year = 2020 ORDER BY hour,minute) ;
3
  • Can you edit your post to add the SQL statement that is giving this error? Once we're able to see how you are trying to use the statement, we will be able to explain what is wrong and how to fix it. Feb 19 at 12:28
  • sure thank you for your heads up
    – Arsham
    Feb 19 at 15:02
  • alright I edited my question
    – Arsham
    Feb 19 at 15:06
1

Your problem is that you have too many ; in your query. You only place a ; at the very end of your SQL query, not at the end of each SELECT statement. Unless you are performing multiple different, unrelated queries or are coding a procedure/function, you will only have a single ;. So, remove all of those and then see if that works.

Also, while I do not do a lot of work in SQL, I have noticed that most of the code I have seen has had each new clause on its own line to make it easier to read, like so:

SELECT
    FROM
    JOIN ON
    WHERE
    ORDER BY
INTERSECT
SELECT
    FROM
...etc

This would also make it easier to spot if a bit of punctuation or something was off, or at least is for me. If that solves the issue, feel free to mark the check next to my answer, but if not leave me a comment with what error it gives and I'll try to help some more.

1
  • Thank you so much for your help this helps a lot :D
    – Arsham
    Feb 19 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .