| Author |
sql question
|
Pranav Sharma
Ranch Hand
Joined: Oct 27, 2003
Posts: 254
|
|
I have TABLE1 with columns 1A 1B 1C(PK) TABLE2 with columns 2A 2B 2C(PK) TABLE3 with columns 3A 3B 3C(PK) TABLE4 with columns 1C 2C 3C 4D my sql = select TABLE1.1A, TABLE1.1B, TABLE1.1C, TABLE2.2A, TABLE2.2B, TABLE2.2C, TABLE3.3A, TABLE3.3B, TABLE3.3C from TABLE1 TABLE1, TABLE2 TABLE2, TABLE3 TABLE3, TABLE4 TABLE4 where ( TABLE4.1C = TABLE1.1C AND TABLE4.2C = TABLE2.2C AND TABLE4.3C = TABLE3.3C AND TABLE4.4D = 'TEST') but my query gives me duplicate rows, when i run select * from TABLE4 where TABLE4.4D = 'TEST' i get about 1500 rows but with actual query i get close 7000 queries, where these counts should be the same. Any help is appreciated
|
 |
Richard Green
Ranch Hand
Joined: Aug 25, 2005
Posts: 536
|
|
select TABLE1.1A, TABLE1.1B, TABLE1.1C, TABLE2.2A, TABLE2.2B, TABLE2.2C, TABLE3.3A, TABLE3.3B, TABLE3.3C from TABLE1 TABLE1, TABLE2 TABLE2, TABLE3 TABLE3, TABLE4 TABLE4 where ( TABLE4.1C = TABLE1.1C AND TABLE4.2C = TABLE2.2C AND TABLE4.3C = TABLE3.3C AND TABLE4.4D = 'TEST')
This should be more readable: select t1.*,t2.*,t3.*,t4.* from table1 t1, table2 t2, table3 t3, table4 t4 where table4.1c = table1.1c and table4.2c = table2.2c and table4.3c = table3.3C and table4.4d = 'test' Can't see whats wrong with that. Suggest that you do two tables at a time and isolate the problem. ie, try select t1.*,t4.* from table1 t1, table4 t4 where table4.1c = table1.1c and table4.4d = 'test' first. and if that works, add t2 and so on.
|
MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
|
 |
Renato Losio
Ranch Hand
Joined: Nov 23, 2005
Posts: 99
|
|
The problem is that your assumption is incorrect: > i get about 1500 rows but with actual query i get close 7000 queries, > where these counts should be the same. Generally speaking, that's not true. Cheers, Renato
|
Renato Losio - www.arsenio.it - renatoweb@arsenio.it
|
 |
Rusty Smythe
Ranch Hand
Joined: Aug 09, 2006
Posts: 93
|
|
Originally posted by Renato Losio: The problem is that your assumption is incorrect: > i get about 1500 rows but with actual query i get close 7000 queries, > where these counts should be the same. Generally speaking, that's not true.
I'd tend to agree. What are the results you get when you run the following two queries? Does leaving the parenthesis off the 'where' clause do anything (should it)?
|
 |
 |
|
|
subject: sql question
|
|
|