February 12, 2025 at 5:51 pm
WHERE a.ROWID IN (SELECT rid
FROM ( SELECT ROWID rid,
row_number() OVER (PARTITION BY c.id ORDER BY c.id) rn
FROM details c
WHERE a.id = c.id
AND c.id > ( SELECT max(id)
FROM details d
WHERE d.id = c.id
AND d.cd = '2030')
AND c.cd IN ( '2017','2012','2021'))
WHERE rn = 1 )
February 12, 2025 at 6:11 pm
Why have you posted a random query? Please ask a question.
February 12, 2025 at 9:51 pm
How to rewrite a query in MS SQL:
WHERE a.ROWID IN (SELECT rid
FROM ( SELECT ROWID rid,
row_number() OVER (PARTITION BY c.id ORDER BY c.id) rn
FROM details c
WHERE a.id = c.id
AND c.id > ( SELECT max(id)
FROM details d
WHERE d.id = c.id
AND d.cd = '2030')
AND c.cd IN ( '2017','2012','2021'))
WHERE rn = 1 )
February 12, 2025 at 9:56 pm
Could we at least have some CREATE TABLE scripts and some INSERT scripts? I'm not feeling that creative today.
What's wrong with the query you have? Does it not work? Or is it really slow? If it's slow but works, then there may be a better way of writing it or a better way of indexing the tables it's using.
February 12, 2025 at 11:42 pm
How to rewrite a query in MS SQL:
WHERE a.ROWID IN (SELECT rid
FROM ( SELECT ROWID rid,
row_number() OVER (PARTITION BY c.id ORDER BY c.id) rn
FROM details c
WHERE a.id = c.id
AND c.id > ( SELECT max(id)
FROM details d
WHERE d.id = c.id
AND d.cd = '2030')
AND c.cd IN ( '2017','2012','2021'))
WHERE rn = 1 )
What dialect of SQL allows a query to start with a WHERE clause?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy