0

I am learning SQL. Using MySQL, I am working on a very simple calendar application. SELECT statement below returns a relation with the schedule ID. And I'd like to delete it using the DELETE statement. So I am trying to delete a specific schedule only in schedule table. But I am getting a syntax error.

ERROR 1064 (42000): You have an error in your SQL syntax;

SELECT s.id 
FROM schedule s, meetings m 
WHERE m.date = s.date AND m.time = s.time AND m.id = 1;
// returns 5

DELETE
FROM schedule s, meetings m 
WHERE m.date = s.date AND m.time = s.time AND m.id = 1;  
// trying to delete the row with id=5 but syntax error

Please help.

10
  • 1
    what error is showing ? Commented Mar 4, 2018 at 9:01
  • if you want to delete from 2 table you should to write 2 query, if you want to delete from one table with this condition(as shown above in your question) you should to join tables together and delete from one you want...now tell us you want to delete from which table dude Commented Mar 4, 2018 at 9:04
  • I am trying to delete only from schedule table Commented Mar 4, 2018 at 9:06
  • @Farrokh He said he wants to delete a schedule. Commented Mar 4, 2018 at 9:06
  • @Barmar i know but i want him to work over his question ;-) Commented Mar 4, 2018 at 9:07

1 Answer 1

4

See the multi-table syntax in the DELETE documentation. The main point is that you have to specify which table(s) you're deleting from after the DELETE keyword:

DELETE s
FROM schedule AS s
JOIN meetings AS m ON m.date = s.date AND m.time = s.time
WHERE m.id = 1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.