Correct mysql statement query

Im trying to write a sql execute where it will delete column1 from first table where it will match column 3 from the next table.
LVL 8
thenoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
> it will delete column1
you mean update the column value to null or empty?

update yourtable
  set column1 = NULL
from yourtable t
join nexttable n
on n.column3 = t.column1
0
thenoneAuthor Commented:
no basically i have a table with a column of records and what i want to do is delete those records that match table2 column 3 records.
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:

delete yourtable
from yourtable t
join nexttable n
on n.column3 = t.column1
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Bob LambersonSoftware EngineerCommented:
thenone,
DELETE table1.columnToDelete
FROM table1 INNER JOIN table2 ON table1.colMatch = table2.colMatch
WHERE (([table1].[colMatch]=[table2].[colMatch]));

Bob
0
thenoneAuthor Commented:
it sais unkown table
0
thenoneAuthor Commented:
what should i put in colMatch
0
Bob LambersonSoftware EngineerCommented:
thenone,
I assume your are putting your table and field names in the corresponding placeholders?

Bob
0
thenoneAuthor Commented:
WHERE (([table1].[colMatch]=[table2].[colMatch])); Yes but I get an error on this line
0
Bob LambersonSoftware EngineerCommented:
thenone,
For the table1 reference, colMatch will be the name of the column that you want to match to a column in table2. The table2 reference to colMatch will be the name of the column that you want to match to the column in table1.
If you want to post the actual column names and table names maybe it would be easier to understand.

Bob
0
Bob LambersonSoftware EngineerCommented:
thenone,
This is an example line........ the table1 should be replaced with your table name. the colMatch should be replaced with your column name, etc.
> WHERE (([table1].[colMatch]=[table2].[colMatch])); Yes but I get an error on this line


Bob
0
thenoneAuthor Commented:
i did that and i get an error 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 '[business_submit].[url]=[business].[url]))' at line 1
0
Bob LambersonSoftware EngineerCommented:
thenone,
Sorry but this is T SQL not MySQL - I don't work with MySQL much so not sure if they are the same syntax.

Here's a ref to MySQL site, and some syntax you can work with
http://dev.mysql.com/doc/refman/5.0/en/delete.html
13.2.1. DELETE Syntax
Multiple-table syntax:

DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
    tbl_name[.*] [, tbl_name[.*]] ...
    FROM table_references
    [WHERE where_condition]

Or:

DELETE [LOW_PRIORITY] [QUICK] [IGNORE]
    FROM tbl_name[.*] [, tbl_name[.*]] ...
    USING table_references
    [WHERE where_condition]

There is also some discussion on that page that may help.

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Guy Hengel [angelIII / a3]Billing EngineerCommented:
delete from [business_submit]
using [business_submit] t,  [business] n
where n.[url] = t.[url]
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
and PLEASE, specify the database ( and version ) you are working with next next questions immediately, saves a lot of time
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.