Help With SQL   Independent houses near kukatpally | Apartments in Pragathi Nagar | AndhraVaani.com | Log Out | Topics | Search
Register | Edit Profile

Bewarse TalkArchives - 2007Cine Talk - Reviews, Gossips, Insider Info etc.Archive through August 16, 2007Help With SQL Previous Next

Author Message
Top of pagePrevious messageNext messageBottom of pageLink to this message

Pda
Celebrity Bewarse
Username: Pda

Post Number: 13722
Registered: 06-2006
Posted From: 70.56.213.83

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 10:39 pm:Edit PostDelete PostView Post/Check IP

ocp ippudu memory test ga ayipoindi mama..dani nunchi nuvvu peddaga espet seyyamaka..
Don't take any decisions when you are angry. Don't make any promises when you are happy.
Top of pagePrevious messageNext messageBottom of pageLink to this message

Rediff
Mudiripoyina Bewarse
Username: Rediff

Post Number: 8258
Registered: 03-2004
Posted From: 71.86.125.171

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 10:31 pm:Edit PostDelete PostView Post/Check IP

btw .. thx mama ..makes sense .. eppudoo confusion naaku aa part ..
Obeying SpeedLimit!! PS: updated on 08/11
Top of pagePrevious messageNext messageBottom of pageLink to this message

Rediff
Mudiripoyina Bewarse
Username: Rediff

Post Number: 8257
Registered: 03-2004
Posted From: 71.86.125.171

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 10:30 pm:Edit PostDelete PostView Post/Check IP

vaake .. nuvvu aa test pass avvadam nammadagina vishayame annamaata ayite


Obeying SpeedLimit!! PS: updated on 08/11
Top of pagePrevious messageNext messageBottom of pageLink to this message

Pda
Celebrity Bewarse
Username: Pda

Post Number: 13720
Registered: 06-2006
Posted From: 70.56.213.83

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 10:25 pm:Edit PostDelete PostView Post/Check IP

oka sare avuddi anukuntaas it is not a correlated subquery
Don't take any decisions when you are angry. Don't make any promises when you are happy.
Top of pagePrevious messageNext messageBottom of pageLink to this message

Rediff
Mudiripoyina Bewarse
Username: Rediff

Post Number: 8254
Registered: 03-2004
Posted From: 71.86.125.171

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 10:19 pm:Edit PostDelete PostView Post/Check IP

select A.PK, A.BK, A.col2, A.col3 from Tbl A
where
A.PK in ( select max(B.PK) from Tbl B group by B.BK );

subquery okka saaari execute avudda or ..does it execute once for every record in A ??
Obeying SpeedLimit!! PS: updated on 08/11
Top of pagePrevious messageNext messageBottom of pageLink to this message

Rediff
Mudiripoyina Bewarse
Username: Rediff

Post Number: 8245
Registered: 03-2004
Posted From: 209.12.236.10

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 3:51 pm:Edit PostDelete PostView Post/Check IP

Gochesh .. so naa select clasue lo 10 columns vunte annintikee aa rank/order logic pettalaa?? chaanallayyindi rank vaadi .. lemme read some theory :-)
Obeying SpeedLimit!! PS: updated on 08/11
Top of pagePrevious messageNext messageBottom of pageLink to this message

Rediff
Mudiripoyina Bewarse
Username: Rediff

Post Number: 8244
Registered: 03-2004
Posted From: 209.12.236.10

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 3:50 pm:Edit PostDelete PostView Post/Check IP

420 mama .. inkaa try cheyalaa.. just back from meeting!!
btw
how is select * from tbl where (pk,bk) in (select max(pk),bk from tbl group by bk) this different from select * from tbl where pk in (select max(pk) from tbl group by bk) ?? when I know for sure that pk by itself is unique and has index on it??

is there going to be any performance/cost improvements??
Obeying SpeedLimit!! PS: updated on 08/11
Top of pagePrevious messageNext messageBottom of pageLink to this message

420
Kurra Bewarse
Username: 420

Post Number: 2259
Registered: 12-2006
Posted From: 85.144.112.59

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 1:22 pm:Edit PostDelete PostView Post/Check IP

Rediff mama .. did you try
Top of pagePrevious messageNext messageBottom of pageLink to this message

420
Kurra Bewarse
Username: 420

Post Number: 2253
Registered: 12-2006
Posted From: 85.144.112.59

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 12:25 pm:Edit PostDelete PostView Post/Check IP

and create a non unique composite index on PK,BK .. and rock and roll
Top of pagePrevious messageNext messageBottom of pageLink to this message

420
Kurra Bewarse
Username: 420

Post Number: 2252
Registered: 12-2006
Posted From: 85.144.112.59

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 12:23 pm:Edit PostDelete PostView Post/Check IP

select * from tbl where (pk,bk) in (select max(pk),bk from tbl group by bk)



waset fellass
Top of pagePrevious messageNext messageBottom of pageLink to this message

Gochi
Bewarse Legend
Username: Gochi

Post Number: 44677
Registered: 07-2004
Posted From: 162.136.192.1

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 12:08 pm:Edit PostDelete PostView Post/Check IP

SELECT max(A.PK) keep (dense_rank first order by A.PK desc) ,
max(A.BK) keep (dense_rank first order by A.PK desc),
max(A.Col1) keep (dense_rank first order by A.PK desc),
max(A.Col2) keep (dense_rank first order by A.PK desc)

from A

where ....


idhi try chesi choodu diffesh...performance emanna improve avvacchu.....
Donate Blood Save Life ! Donate Eyes Live Twice
Top of pagePrevious messageNext messageBottom of pageLink to this message

Rediff
Mudiripoyina Bewarse
Username: Rediff

Post Number: 8243
Registered: 03-2004
Posted From: 209.12.236.10

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 11:46 am:Edit PostDelete PostView Post/Check IP

SOURCE idi ayite
PKBKc1c2
11abcdef
22aadd
33aaff
42bbdd
52assd
66asdaadsa


result idi raavali
PKBKc1c2
11abcdef
33aaff
52assd
66asdaadsa

Obeying SpeedLimit!! PS: updated on 08/11
Top of pagePrevious messageNext messageBottom of pageLink to this message

Nine
Pilla Bewarse
Username: Nine

Post Number: 486
Registered: 04-2005
Posted From: 144.42.9.182

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 11:46 am:Edit PostDelete PostView Post/Check IP

yeah.. my 1st post assumption was incorrect. i see another group by inside which does the job.

index create chesaka.. either 2 or 3 best methods.

gochesh: PK unique key .. BK is natural key.. which has duplicate rows. latest BK ki equalant PK ni match cheyyali. adi diff kochen.
nenu ee patrikaku hater ni kaadu. patrika musugu lo swardha puritha siddanthalanu vallinche vaarante asahyam!
Top of pagePrevious messageNext messageBottom of pageLink to this message

Rediff
Mudiripoyina Bewarse
Username: Rediff

Post Number: 8242
Registered: 03-2004
Posted From: 209.12.236.10

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 11:44 am:Edit PostDelete PostView Post/Check IP

>>so neeku PK value,max(bk) value and corresponding other columns values for this Max(bk) kaavali...anthenaa

.. tappu .. BK value and other values from record with Max(PK)
Obeying SpeedLimit!! PS: updated on 08/11
Top of pagePrevious messageNext messageBottom of pageLink to this message

Rediff
Mudiripoyina Bewarse
Username: Rediff

Post Number: 8241
Registered: 03-2004
Posted From: 209.12.236.10

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 11:42 am:Edit PostDelete PostView Post/Check IP

thx mama .. actual gaa Q2 kooda correct results e istundi ..

inkaa emanna better method vundemo ani aduguthunna .. anthe ..
PK and BK meeda Indexes create chestunnam ..
Obeying SpeedLimit!! PS: updated on 08/11
Top of pagePrevious messageNext messageBottom of pageLink to this message

Nine
Pilla Bewarse
Username: Nine

Post Number: 485
Registered: 04-2005
Posted From: 144.42.9.182

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 11:42 am:Edit PostDelete PostView Post/Check IP

hmm.. i guess.. logical ga.. 2nd query kuda equal result return chestundi.. inclusion merge join chesi.

order of cost high to low:

1 > 2 = 3

internal ga 2nd and 3rd same processing logic use chestayi.

create an index on table B (PK, BK) columns for performance improvement.
nenu ee patrikaku hater ni kaadu. patrika musugu lo swardha puritha siddanthalanu vallinche vaarante asahyam!
Top of pagePrevious messageNext messageBottom of pageLink to this message

Gochi
Bewarse Legend
Username: Gochi

Post Number: 44671
Registered: 07-2004
Posted From: 162.136.192.1

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 11:41 am:Edit PostDelete PostView Post/Check IP

Diffesh,sarigga artham kaaledhu...

Pk is primary key in ur table annavu...daaniki multiple BK's unnayi...so neeku PK value,max(bk) value and corresponding other columns values for this Max(bk) kaavali...anthenaa
Donate Blood Save Life ! Donate Eyes Live Twice
Top of pagePrevious messageNext messageBottom of pageLink to this message

Ravanabrahma
Yavvanam Kaatesina Bewarse
Username: Ravanabrahma

Post Number: 3841
Registered: 06-2004
Posted From: 65.196.167.82

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 11:40 am:Edit PostDelete PostView Post/Check IP

PK ante primary key ani ardamaindi kani BK endi. backup key naa. naaku theliyadu. evaranna septhe sootha
Top of pagePrevious messageNext messageBottom of pageLink to this message

Nine
Pilla Bewarse
Username: Nine

Post Number: 484
Registered: 04-2005
Posted From: 144.42.9.182

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 11:39 am:Edit PostDelete PostView Post/Check IP

2nd query incorrect. adi equalent result return cheyyadu. subquery returns the max of the whole table, not the respective key.

1st and 3rd lo queries lo 3rd cost effective.
nenu ee patrikaku hater ni kaadu. patrika musugu lo swardha puritha siddanthalanu vallinche vaarante asahyam!
Top of pagePrevious messageNext messageBottom of pageLink to this message

Rediff
Mudiripoyina Bewarse
Username: Rediff

Post Number: 8240
Registered: 03-2004
Posted From: 209.12.236.10

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 11:35 am:Edit PostDelete PostView Post/Check IP

also is there any diff between Q2 and Q3 .. in the way how they get executed??
Obeying SpeedLimit!! PS: updated on 08/11
Top of pagePrevious messageNext messageBottom of pageLink to this message

Rediff
Mudiripoyina Bewarse
Username: Rediff

Post Number: 8239
Registered: 03-2004
Posted From: 209.12.236.10

Rating:N/A
Votes: 0(Vote!)

Posted on Tuesday, August 14, 2007 - 11:34 am:Edit PostDelete PostView Post/Check IP

maamaloo .. here is my requirement .. there are multiple records in table for given BK value and PK value is unique across table. I need to pull Max(PK), bunch of other cols from corresponding record, for each combination of BK ..

Here are couple of ways to do that .. to the best of my knowledge!!


select A.PK, A.BK, A.col2, A.col3 from Tbl A
where
A.PK in ( select max(B.PK) from Tbl B where B.BK = A.BK );



select A.PK, A.BK, A.col2, A.col3 from Tbl A
where
A.PK in ( select max(B.PK) from Tbl B group by B.BK );



select A.PK, A.BK, A.col2, A.col3 from Tbl A, (select max(B.PK) as PK from Tbl B group by B.BK ) C_MAX_TBL
where A.PK = C_MAX_TBL.PK



e queries cost elaa vuntundi .. which is constlier that the other??

My table has about 2M records and there are about 1.9M unique combinations of BK..
Given this info .. is there any better method??
Obeying SpeedLimit!! PS: updated on 08/11