Q
Problem solve Get help with specific problems with your technologies, process and projects.

Different query results with an additional SELECT column

I have 2 SQL queries with the same joins and where conditions. The only difference is the second SQL contains an...

additional field in the select statement. Query 1 returns NO rows, while query 2 returns many rows. The explain plans of these 2 queries are also different. Please help with an explanation if you can. Is there something in Oracle that requires certain fields to be in the select statement in order for certain joins to generate results?

Query 1:

SELECT al2.target_name, al4.location_cd
  FROM DDW_RTP.KINASE_PIC50 AL1
     , DDW_DBA.TARGET AL2
     , DDW_DBA.SCREEN AL4
     , DDW_DBA.SCREEN_PROPERTIES AL5
     , DDW_DBA.COMPOUND AL7
     , DDW_RTP.COMPOUND_CALC_PROPERTIES AL11
 WHERE ( AL7.MOLNAME = AL11.MOLNAME(+)
     AND AL2.TARGET_KEY=AL1.TARGET_KEY
     AND AL4.SCREEN_KEY=AL1.SCREEN_KEY
     AND AL5.TECHNOLOGY_KEY=AL1.TECHNOLOGY_KEY
     AND AL7.COMPOUND_LOT_KEY=AL1.COMPOUND_LOT_KEY )
   AND ( AL2.TARGET_NAME = 'ALK5'
     AND AL4.LOCATION_CD = 'HAR'
     AND AL5.ASSAY_FORMAT = 'FP'
     AND AL5.ASSAY_SUBTYPE = 'Binding' )

Query 2:

SELECT al2.target_name, al4.location_cd, al5.assay_subtype
  FROM DDW_RTP.KINASE_PIC50 AL1
     , DDW_DBA.TARGET AL2
     , DDW_DBA.SCREEN AL4
     , DDW_DBA.SCREEN_PROPERTIES AL5
     , DDW_DBA.COMPOUND AL7
     , DDW_RTP.COMPOUND_CALC_PROPERTIES AL11
 WHERE ( AL7.MOLNAME = AL11.MOLNAME(+)
     AND AL2.TARGET_KEY=AL1.TARGET_KEY
     AND AL4.SCREEN_KEY=AL1.SCREEN_KEY
     AND AL5.TECHNOLOGY_KEY=AL1.TECHNOLOGY_KEY
     AND AL7.COMPOUND_LOT_KEY=AL1.COMPOUND_LOT_KEY )
   AND ( AL2.TARGET_NAME = 'ALK5'
     AND AL4.LOCATION_CD = 'HAR'
     AND AL5.ASSAY_FORMAT = 'FP'
     AND AL5.ASSAY_SUBTYPE = 'Binding' )

Interesting. Most interesting. I'm sorry, I really cannot understand why query 1 should return no rows while query 2 returns many. Perhaps by the time you see this answer, the data will have changed, and you will get consistent results. Perhaps there was a problem with the indexes.

With regard to the difference in EXPLAIN PLANs, this is a bit tricky to understand, too. Ordinarily, the addition of a column to the SELECT list can change the execution plan if this column is not involved in joining tables. If rows can be tested for inclusion by examining index columns without retrieving actual row data, the execution plan will be different than if the row has to be retrieved in order to test a column that is not in an index. But in your example, the extra column (al5.assay_subtype) is involved in the join, and has the same predicate in both queries --

     AND AL5.ASSAY_SUBTYPE = 'Binding'

The only comment I can offer is that if you're going to test for a specific value of a column, there's not much point in adding it to the SELECT list -- might just as well add the literal character string instead.

The answer to your final question, "Is there something in Oracle that requires certain fields to be in the select statement in order for certain joins to generate results?" is "No."

Ask your DBA to try going back and regenerating your indexes. If you still get the disparity, consider asking Oracle Corporation for additional help.

For More Information

  • What do you think about this answer? E-mail the edtiors at editor@searchDatabase.com with your feedback.
  • The Best SQL Web Links: tips, tutorials, scripts, and more.
  • Have an SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
  • Ask your technical SQL questions -- or help out your peers by answering them -- in our live discussion forums.
  • Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.

This was last published in February 2002

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close