Sql Query help

01/17/2014 17:51 Mslolita#1
Hello,

i like to ask for help. to create a sql query to remove unwanted accounts in the database for example

Database Auth= Table Accounts

Field Name:
Account

test
test1
test2
test3
test4
test5

Database Telecaster = Table Characters

Field Name:
Account

test2
test3
test4
test5

i like to run a query to remove all account records in Database Auth except if they exist in the Database Table characters (Field name Account)

in this case it should remove test and test 1 and keep test2/3/4/5 in both
if there is anyone that is able to help me it would be great!
01/17/2014 20:34 malaysiawap#2
this is just example delete the name value LIKE 'test'

SELECT * FROM [Auth].[dbo].[Account] WHERE account LIKE '%test%'

if value to delete exists, just run the query below

DELETE FROM [Auth].[dbo].[Account] WHERE account LIKE '%test%'

do same for character..

and here some query code to remove the deleted char.

SELECT * FROM [Telecaster].[dbo].[Character] WHERE name LIKE '%@%'

DELETE FROM [Telecaster].[dbo].[Character] WHERE name LIKE '%test%'
01/17/2014 21:19 ThunderNikk#3
That's nice but it will delete all accounts with 'test' in the name regardless if there are created characters or not.

So if someone created an account named 'johnnytest' it will be deleted.

I think the OP wants to delete all accounts that never created a character.
01/17/2014 23:04 TheSuperKiller#4
use auth delete from accounts where account_id not in (select account_id from telecaster.dbo.Character)
01/18/2014 01:14 Mslolita#5
Thank you very much!

Quote:
Originally Posted by TheSuperKiller View Post
use auth delete from accounts where account_id not in (select account_id from telecaster.dbo.Character)