/    Sign up×
Community /Pin to ProfileBookmark

Hi, can someone please help me out with this MySQL query. It should be simple but i’m not sure why it is not working, so any help would be appreciated!

DELETE FROM posts, posts_text WHERE posts.post_id=posts_text.post_id AND posts.post_username LIKE ‘%@%’

Here’s the error I get…
#1064 – You have an error in your SQL syntax.**Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘where posts.post_id=posts_text.post_id and posts.po

Any help will be greatly appreciated.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@Stephen_PhilbinAug 09.2005 — Does back-tick quoting yer table names help?

DELETE FROM <span><code>posts</code></span>,<span><code>posts_text</code></span> WHERE <span><code>posts</code></span>.<span><code>post_id</code></span>=<span><code>posts_text</code></span>.<span><code>post_id</code></span> AND <span><code>posts</code></span>.<span><code>post_username</code></span> LIKE '%@%'
Copy linkTweet thisAlerts:
@aznchong91Aug 10.2005 — maybe its the AND part. It could be something else. I don't know, since I don't use AND normally, only in php where it is &&.
Copy linkTweet thisAlerts:
@RhathidAug 10.2005 — I don't believe you can use "like" in a delete statement, it wouldn't really be a smart function for a database.

You'll need to do two queries, select everything using the like statement and then use the returned recordset to delete everything matching it.
Copy linkTweet thisAlerts:
@artoAug 10.2005 — [CODE]DELETE FROM posts, posts_text WHERE posts.post_id=posts_text.post_id AND posts.post_username LIKE '%@%'[/CODE][/QUOTE]According to [URL=http://dev.mysql.com/doc/mysql/en/delete.html]http://dev.mysql.com/doc/mysql/en/delete.html[/URL], your syntax is wrong. You must use either [CODE]DELETE ... FROM ... WHERE ...[/CODE] or [CODE]DELETE FROM ... USING ... WHERE ...[/CODE]Arto
Copy linkTweet thisAlerts:
@NogDogAug 10.2005 — Try this:
<i>
</i>DELETE posts, posts_text FROM posts, posts_text
WHERE posts.post_id=posts_text.post_id AND posts.post_username LIKE '%@%'
×

Success!

Help @Cowboy_Killer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...