none
INNER Join question RRS feed

  • Question

  • I have a Select query that returns some data. Once i have the query it returns 2 rows. As soon as i add another inner join to another table it returns 1 row. How could i see where the problem is? Or anyway to return the correct number of rows?

    I would have posted some SQL code but i assume this may add further confusion however if you would like to see it please advise.

    Thanks

    Sunday, September 9, 2012 3:39 PM

Answers

  • Hi,

    What is the purpose for which you are adding an inner join ? I would ask you to refer back to the basics of SET theory and consequently the workings of a JOIN. the inner join is essentially an INTERSECTION of 2 data sets. This means that only the data that is common between the 2 sets will be returned. That is why, your first query would return 2 rows but after you add an inner join, it returns only 1 row, because there is only 1 row matching your join column between the 2 tables.

    Feel free to post the table DDL, scripts for data as well as your SQL Query code so that we can explain this better.

    Please follow this link for a detailed explanation with an example - http://www.w3schools.com/sql/sql_join_inner.asp


    Sanil Mhatre | Database Developer | MCTS | If you find my reply useful in any way, please vote it as helpful. If it has helped answer your question, please mark it as Answer. http://sqlwithsanil.com

    Sunday, September 9, 2012 3:50 PM

All replies

  • Hi, the easiest way for people to help with a question like this is to post the DDL/create table statements, sample data, and expected results (ex:  why is it that you think it should only return one result in this case, etc.).

    Thanks,
    Sam Lester (MSFT)


    My Blog

    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

    Sunday, September 9, 2012 3:46 PM
    Moderator
  • Hi,

    What is the purpose for which you are adding an inner join ? I would ask you to refer back to the basics of SET theory and consequently the workings of a JOIN. the inner join is essentially an INTERSECTION of 2 data sets. This means that only the data that is common between the 2 sets will be returned. That is why, your first query would return 2 rows but after you add an inner join, it returns only 1 row, because there is only 1 row matching your join column between the 2 tables.

    Feel free to post the table DDL, scripts for data as well as your SQL Query code so that we can explain this better.

    Please follow this link for a detailed explanation with an example - http://www.w3schools.com/sql/sql_join_inner.asp


    Sanil Mhatre | Database Developer | MCTS | If you find my reply useful in any way, please vote it as helpful. If it has helped answer your question, please mark it as Answer. http://sqlwithsanil.com

    Sunday, September 9, 2012 3:50 PM
  • I would have posted some SQL code but I assume this may add further confusion however if you would like to see it please advise. 

    NO! Do you program without an DDL or specs? Did you read the "Basic Netiquette" at the front of every SQL forum on the Internet? 


    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking in Sets / Trees and Hierarchies in SQL

    Sunday, September 9, 2012 7:18 PM