Asking
Only logged in members can reply and interact with the post.
Join SimilarWorlds for FREE »

Anyone familiar with MySQL. Why DELETE FROM doesn't work but ;DELETE FROM works?

Northwest · M
It worked.

Delete * from sometable where id=5
;
You hit return after the first line, but MySQL is waiting for the ; to execute the statement. When you enter the ; and hit return, the delete statement is properly executed.

The remainder of that line: Delete from.. does not execute. It’s waiting for an ;
Sharon · F
Most MySQL statements require a ; at the end. I'm guessing that initial ; is ending a previous statement. What is the full query you're trying to run?
Riemann · 31-35, M
Riemann · 31-35, M
Check pls @MartinTheFirst
Sharon · F
@Riemann

[quote]UPDATE mytable SET username="myuser" WHERE id=8
DELETE FROM mytable WHERE id=8[/quote]

The UPDATE line needs to end with a ';'. The reason ;DELETE... works is because it treats that initial ';' as the end of the previous line.

Change it to -
UPDATE mytable SET username="myuser" WHERE id=8;
DELETE FROM mytable WHERE id=8;

Some statements will work without a ';' at the end but it's best to always use one anyway.

It's also a good idea to enclose table and field names in backticks to avoid conflict with keywords of the same name. e.g.

UPDATE `mytable` SET `username` = "myuser" WHERE `id` = 8;
DELETE FROM `mytable` WHERE `id` = 8;
ABCDEF7 · M
First end your previous query by using ";" at the end of previous line. Then the next Delete query should be followed.

Interpreter is considering both delete and previous query to delete as one. Which they are not actually, and neither they both makes a valid syntax of a query.
Sorry , I'm only familiar with MS Sql Server.
mylasttimehere · 26-30, M
Lol?

It's too obvious right?
Riemann · 31-35, M
@mylasttimehere non
m newbie
Senecaa · 70-79, M
What does DELETE FROM do?
Riemann · 31-35, M
@Senecaa Removes a row with a given id
Senecaa · 70-79, M
Thanks just curious 🤔
MartinTheFirst · 22-25, M
;DELETE FROM means youre starting a new line
Riemann · 31-35, M
@MartinTheFirst Trying to delete a row. The Select and delete shows greensign with 0 rows being affected
Riemann · 31-35, M
@MartinTheFirst This is the full set of codes that are trying:

CREATE DATABASE mydb;
USE mydb;
CREATE TABLE mytable
(
id int unsigned NOT NULL auto_increment,
username varchar(100) NOT NULL,
email varchar(100) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO mytable (username, email )
VALUES ( "myuser", "myuser@example.com" );
UPDATE mytable SET username="myuser" WHERE id=8
DELETE FROM mytable WHERE id=8
MartinTheFirst · 22-25, M
@Riemann dude again you need to write ";" at the end of each command

 
Post Comment