Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

sql question  RSS feed

 
Ranch Hand
Posts: 261
  • 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
 
Ranch Hand
Posts: 536
  • 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.
 
Ranch Hand
Posts: 99
  • 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
 
Ranch Hand
Posts: 93
Mac Objective C Ruby
  • 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
Boost this thread!