My SELECT statement works, but I'm unable to DELETE

David

I've got a working SQL query that returns information that needs to be removed from the database. I'm having a hard time using this information to delete the records.

I'm using a mySQL database and I'm trying to make these changes using HeidiSQL.

The code that works to select the data is:

SELECT * 
FROM users u 
WHERE NOT EXISTS 
    (SELECT 1 
     from users_classdetails uc 
     WHERE u.id = uc.userID 
         AND dateEntered > DATE_SUB(NOW(),INTERVAL 3 YEAR) ) 
AND bestcontact = ""

And I hoped to be able to use something like:

DELETE 
FROM users u 
WHERE NOT EXISTS 
    (SELECT 1 
     from users_classdetails uc 
     WHERE u.id = uc.userID
        AND dateEntered > DATE_SUB(NOW(),INTERVAL 3 YEAR) )
AND bestcontact = ""

But I'm shown an error 1064 that explains my syntax is wrong. It points out the WHERE NOT EXISTS ( SELECT 1 from users_classdetails as the problem. I'm not sure why it would be valid for SELECT but not DELETE. Any help would be greatly appreciated.

Nathan

you can't use table aliasing and must use the full table name in the NOT EXISTS part of the query.

Source

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I select a project in my Podfile? I'm getting the error: Unable to find the Xcode project for the target 'Pods'

From Dev

unable to delete my file in ios

From Dev

Prepared statement works for INSERT but not for SELECT

From Dev

INNER JOIN works as SELECT but not as DELETE

From Dev

As soon as i add an item to my array i am unable to delete an item from my array

From Dev

Converting my Nested Select Statement to an Update Statement

From Dev

MySql prepared statement is not working for SELECT,but works for all other statement

From Dev

ORA-00979, but I have elements in my SELECT in my GROUP BY statement

From Dev

I'm trying to create an AutoCompleteTextView in my android app. Trouble is, I'm unable to customize it

From Dev

I cant select the delete class in my jquery

From Dev

I'm unable to find a result in my div

From Dev

How should I add text to my column's select statement

From Dev

How can I make my select statement deterministically match only 1/n of my dataset?

From Dev

Write a SQL delete based on a select statement

From Dev

Why can't I use a CTE in my select statement?

From Dev

I am having an error in SQLite statement ON DELETE CASCADE statement in my quiz app

From Dev

I'm missing a break statement in my IF statement

From Dev

unable to delete my file in ios

From Dev

Prepared statement works for INSERT but not for SELECT

From Dev

Unable to update table, but select works

From Dev

Re-writing my query to delete from a select statement

From Dev

INNER JOIN works as SELECT but not as DELETE

From Dev

How do I add my order by field to this select statement?

From Dev

ORA-00979, but I have elements in my SELECT in my GROUP BY statement

From Dev

Mysql Take select * statement and turn it in to a delete statement

From Dev

I'm unable to mount my USB drive

From Dev

I'm unable to delete an existing localstorage value in backbone.js

From Dev

expect statement works for $scope, how do I get my init() function in Karma test?

From Dev

How can i select combine category name in my SQL select statement?

Related Related

  1. 1

    How do I select a project in my Podfile? I'm getting the error: Unable to find the Xcode project for the target 'Pods'

  2. 2

    unable to delete my file in ios

  3. 3

    Prepared statement works for INSERT but not for SELECT

  4. 4

    INNER JOIN works as SELECT but not as DELETE

  5. 5

    As soon as i add an item to my array i am unable to delete an item from my array

  6. 6

    Converting my Nested Select Statement to an Update Statement

  7. 7

    MySql prepared statement is not working for SELECT,but works for all other statement

  8. 8

    ORA-00979, but I have elements in my SELECT in my GROUP BY statement

  9. 9

    I'm trying to create an AutoCompleteTextView in my android app. Trouble is, I'm unable to customize it

  10. 10

    I cant select the delete class in my jquery

  11. 11

    I'm unable to find a result in my div

  12. 12

    How should I add text to my column's select statement

  13. 13

    How can I make my select statement deterministically match only 1/n of my dataset?

  14. 14

    Write a SQL delete based on a select statement

  15. 15

    Why can't I use a CTE in my select statement?

  16. 16

    I am having an error in SQLite statement ON DELETE CASCADE statement in my quiz app

  17. 17

    I'm missing a break statement in my IF statement

  18. 18

    unable to delete my file in ios

  19. 19

    Prepared statement works for INSERT but not for SELECT

  20. 20

    Unable to update table, but select works

  21. 21

    Re-writing my query to delete from a select statement

  22. 22

    INNER JOIN works as SELECT but not as DELETE

  23. 23

    How do I add my order by field to this select statement?

  24. 24

    ORA-00979, but I have elements in my SELECT in my GROUP BY statement

  25. 25

    Mysql Take select * statement and turn it in to a delete statement

  26. 26

    I'm unable to mount my USB drive

  27. 27

    I'm unable to delete an existing localstorage value in backbone.js

  28. 28

    expect statement works for $scope, how do I get my init() function in Karma test?

  29. 29

    How can i select combine category name in my SQL select statement?

HotTag

Archive