File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sql question

 
Pranav Sharma
Ranch Hand
Posts: 258
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 536
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Renato Losio
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rusty Smythe
Ranch Hand
Posts: 93
Mac Objective C Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic