473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SQL Delete prob.

Hi
my prob is like this..
-----------------------------
create table ax(
i int ,
j int
)

create table ay(
i int ,
j int
)

insert into ax values(1,100)
insert into ax values(1,101)
insert into ax values(2,103)

insert into ay values(1,200)
insert into ay values(1,201)
insert into ay values(1,202)
insert into ay values(2,203)
insert into ay values(2,204)
insert into ay values(2,205)

select * from ax
select * from ay
--------------------

I want to delete
2 records(count of ax.i = 1) from ay.i = 1 and
1 record(count of ax.i = 2) from ay.i = 2

expected result :
select * from ay
i , j
-----
1 , any data
2 , any data
2 , any data
note: j is the temporary column in both table.

thanks
dishan

Jul 23 '05 #1
2 1401
On 12 Jan 2005 23:02:17 -0800, Dishan Fernando wrote:

(snip)
I want to delete
2 records(count of ax.i = 1) from ay.i = 1 and
1 record(count of ax.i = 2) from ay.i = 2

expected result :
select * from ay
i , j
-----
1 , any data
2 , any data
2 , any data
note: j is the temporary column in both table.


Hi Dishan,

DELETE FROM ay
WHERE (SELECT COUNT(*)
FROM ay AS ay2
WHERE ay2.i = ay.i
AND ay2.j < ay.j) <
(SELECT COUNT(*)
FROM ax
WHERE ax.i = ay.i)

SELECT i, j
FROM ay

i j
----------- -----------
1 202
2 204
2 205

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2
Thanks.. It works !!!!

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David B | last post by:
I am trying to delete the data from 4 fields from a record but leaving the ScheduleDetailsID untouched. Even if I take out the .ScheduleDetailsID from the delete line it comes back DELETE...
2
by: Jason Shohet | last post by:
I don't know what this folder does, but in c, winnt, microsoft.net, framework, v1.1.4322, its there. I'm getting an error on one of my web sites saying that 'art.global' is defined in...
0
Savage
by: Savage | last post by:
I'm making for fun a simple program which format a input file.Input file sustain of person name,lastname and date of birth.Output file si supposed to be forammted as following: NAME ...
2
by: mnacw | last post by:
Can anybody help me to resolve this prob. i have installed Visual Studio 2005 Professional edition. I am working in VB.Net. When I tried to connect to database it is connected but when i make some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.