Win a copy of Java Challengers this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Correlation in SQL to distinguish tables

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

If my query makes any sense...perhaps someone can explain how correlation affects it?

My SQL error message:

Tables or functions 'MainProduct' and 'MainProduct' have the same exposed names. Use correlation names to distinguish them.

My SQl Statement:

Select MainProduct.Title, MainProduct.Descr, MainProductType.Descr, NolaProductInfo.IERID, NolaSubBasin.Name, NolaVicinity.Name
From MainProduct, NolaProductInfo
LEFT JOIN NolaSubBasin on NolaProductInfo.SubBasinID = NolaSubBasin.ID
LEFT JOIN NolaVicinity on NolaProductInfo.VicinityID = NolaVicinity.ID
LEFT JOIN MainProduct on MainProductType.ProdTypeCode = MainProduct.ProdTypeCode
where(MainProduct.ProdId = 24350 And NolaProductInfo.ProdId = 24350)
[ March 10, 2008: Message edited by: jite eghagha ]
 
author & internet detective
Posts: 40536
825
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jite,
The MainProduct table appears in your query twice. The message means to give each one a name: "From MainProduct product1" and reference the columns as "product1.Title".
 
jite eghagha
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, but i get the same error:

The correlation name 'product1' has the same exposed name as table 'product1'.


assuming the sql below is correct:


Select MainProduct.Title, MainProduct.Descr, MainProductType.Descr, NolaProductInfo.IERID, NolaSubBasin.Name, NolaVicinity.Name
From MainProduct product1, MainProduct product2, NolaProductInfo
LEFT JOIN NolaSubBasin on NolaProductInfo.SubBasinID = NolaSubBasin.ID
LEFT JOIN NolaVicinity on NolaProductInfo.VicinityID = NolaVicinity.ID
LEFT JOIN product1 on MainProductType.ProdTypeCode = product2.ProdTypeCode
where(MainProduct.ProdId = 24350 And NolaProductInfo.ProdId = 24350)
 
Jeanne Boyarsky
author & internet detective
Posts: 40536
825
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jite,
That's part of the way there. You need to use the product1/2 aliases in the select, not just the where clause. For example:


If the select refers to "MainProduct", the database doesn't know which of them you want.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic