If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > delete query help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-25-08, 09:03
khdani khdani is offline
Registered User
 
Join Date: Nov 2008
Posts: 20
delete query help

Hello,
I've two tables
1) Governor_Of(governor_name, state_name)
2) Mayor_Of(mayor_name,city_name)

I want to delete a row of governor where a state is governed by more than one governor including this which i want to delete and that governor is not a mayor.
For example:
Governor_Of
_________
Michael NY
George NY

Mayor_Of
________
Michael NYCity

I want to delete George from Governor_Of
Please help....

Thank You
Reply With Quote
  #2 (permalink)  
Old 12-25-08, 09:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,511
your tables are very weird, this sounds far too much like a homework assignment

please show us what you have tried yourself
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-25-08, 09:12
khdani khdani is offline
Registered User
 
Join Date: Nov 2008
Posts: 20
i've tried, this

Code:
DELETE FROM Governor_Of
WHERE governor_name NOT IN (SELECT mayor_name FROM Mayor)
AND governor_name IN (SELECT governor_name, COUNT(state_name)
		FROM Governor_Of
		GROUP BY governor_name
		HAVING COUNT(state_name) > 1
	)
;
but it says too many values in line 3 at SELECT
Reply With Quote
  #4 (permalink)  
Old 12-25-08, 10:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,511
remove the COUNT from the SELECT clause of the subquery

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On