Jump to content

[SOLVED] Whats wrong with this query?


gangsterwanster1

Recommended Posts

Missing a ).

 

 

This should work :).

 

 

<?php
$connect = mysql_connect("127.0.0.1", "root", "") or die('Could not connect');
    mysql_select_db("MainDB", $connect) or die('Could not select database');
    $query = mysql_query("delete bad_rows.*
                    from account as good_rows
                       inner join account as bad_rows on bad_rows.username = good_rows.username and
                                         bad_rows.id > good_rows.id)", $connect) or die(mysql_error());
    mysql_close($connect) or die(mysql_error());
?>

AHHHH

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 ')' at line 4

 

Link to comment
Share on other sites

That would leave him with an extra ) inside the query, at the very end.

Why can't you just make it a bit less confusing?

$connect = mysql_connect("127.0.0.1", "root", "") or die('Could not connect');
    mysql_select_db("MainDB", $connect) or die('Could not select database');

$sql = "DELETE bad_rows.*
       FROM account
        AS good_rows
       INNER JOIN account
        AS bad_rows
          ON (bad_rows.username = good_rows.username
            AND
              bad_rows.id > good_rows.id)";

$query = mysql_query($sql, $connect) or die(mysql_error());
mysql_close($connect) or die(mysql_error());

Link to comment
Share on other sites

That would leave him with an extra ) inside the query, at the very end.

Why can't you just make it a bit less confusing?

$connect = mysql_connect("127.0.0.1", "root", "") or die('Could not connect');
    mysql_select_db("MainDB", $connect) or die('Could not select database');

$sql = "DELETE bad_rows.*
       FROM account
        AS good_rows
       INNER JOIN account
        AS bad_rows
          ON (bad_rows.username = good_rows.username
            AND
              bad_rows.id > good_rows.id)";

$query = mysql_query($sql, $connect) or die(mysql_error());
mysql_close($connect) or die(mysql_error());

Finally!! Thanks a LOT everyone, finally solved it.

 

~i have one minor question with the code you posted and then i am done.

If i wanted it to delete duplicates based on more then one row would i do this?

 

ON (bad_rows.username = good_rows.username
            AND
ON (bad_rows.password = good_rows.password
            AND
              bad_rows.id > good_rows.id)";

 

 

Because i tried that and it comes up with this erorr;

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 'ON (bad_rows.password = good_rows.password AND bad_r' at line 8

 

Link to comment
Share on other sites

I believe you would just add to the AND conditions

...
ON (bad_rows.username = good_rows.username
            AND
              bad_rows.id > good_rows.id
            AND
              bad_rows.something = good_rows.something)

 

Is that what you mean, or am I misunderstanding?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.