Inner join give multiple rows

Proposed Inner join give multiple rows

  • Thursday, January 31, 2013 10:13 AM
     
     

    Hi Friends

    I cannot get why Inner join give me error like this ..

    Actually i'm using

    select caller_code from  call_log
    where caller_code='508'

    select phone_number from  vicidial_list
    where phone_number='508'

    Both return me two row.

    but when join both on based of caller_code and phone_number then it return me 4 rows ..

    kindly help me .. how can i resolve this and get matching value based on aller_code and phone_number ?

    Please help

All Replies

  • Thursday, January 31, 2013 10:17 AM
     
     

    Whats your joing query?

    Try the below:

    Select * From Call_log A

    Inner Join vicidial_list B On A.Caller_code = B.Phone_number


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

  • Thursday, January 31, 2013 10:18 AM
    Answerer
     
     
    What is desired output? Take a look at DISTINCT clause.

    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Blog: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance

  • Thursday, January 31, 2013 10:18 AM
     
      Has Code

    Which JOIN type you are using? Try this query. If you can give some sample data it will help us to understand the exact issue.

    select caller_code,phone_number from  call_log c
    JOIN vicidial_list l ON c.caller_code=l.phone_number
    where c.caller_code='508'
     

    Thanks,

    Saikat

  • Thursday, January 31, 2013 10:25 AM
     
     Proposed

    Obviously..

    you have two records in caller_code

    508 in caller_code match with 2 records 508 in Phone_number

    Same will repeat for another 508 of caller_code because it is matching.

    Regards,Eshwar.


    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.



  • Thursday, January 31, 2013 10:28 AM
     
     

    like if i use

    select phone-numebr from list then it return me

    508
    508
    508

    then if i use

    select caller_code from log then it return me

    508
    508
    508

    now when i use  inner join

    select phone-number from list LL

    Inner join (select caller_code from log) LG

    On LL. phone_number = LL.caller_code

    Then it return me

    508
    508
    508

    508
    508
    508

    508
    508
    508

    and it should return

    508

    508

    508   only three times

    • Edited by BI_group Thursday, January 31, 2013 10:33 AM
    •  
  • Thursday, January 31, 2013 10:32 AM
    Answerer
     
     
    yes, because 3*3 =9 no? what output did you need?

    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Blog: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance

  • Thursday, January 31, 2013 10:44 AM
     
     

    it should return matching rows in table 1 that is should return all rows in table 1  and based on phone-number return other column from table 2 ..

    I.e. as first table row count is 3 so i need 3 rows.

  • Thursday, January 31, 2013 10:49 AM
    Answerer
     
     

    No, based on the data  you posted here. Please read this book http://www.sql.co.il/books/tsqlfund2008/

    If it does not help, please post CREATE TABLE+ Sample Data+ Desired result


    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Blog: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance

  • Thursday, January 31, 2013 12:02 PM
     
     Proposed Has Code

    Try below code.

    select LL.phone_number from list LL
    
    where exists (select 1 from log LG where LG.caller_code = LL.phone_number)



    Bharath T

    • Proposed As Answer by tBharatht Thursday, January 31, 2013 1:09 PM
    •