a simple join

  • hello everybody

    I have a problem that to me is simple, I guess!, we have 2 tables, and I want to do a join with only a field,

    Select t1.campo1, t1.campo2

    from tabla1 t1 join tabla2 t2

    on t1.rfc = t2.rfc

    this return only a single result and when I do how the follow

    Select t1.campo1, t1.campo2

    from tabla1 t1

    on t1.rfc in ('FAA9905073B9','FCO011107EP2','FRE920401VD8','POL790226L74')

    where the last line are some of the fields that we have searched, and the result returned have is more that one row.

    I guess that the version isn’t important, but it’s SQL 2014 Enterprise with windows 2012 server

    Thanks for you help, that have a nice day.

    :w00t:

    Angel Miranda Nieto
    DBA Specialist, BI, MCSA SQL Server

  • Run the following and post the results:

    Select

    t1.campo1,

    t1.campo2

    from

    tabla1 t1

    join tabla2 t2

    on t1.rfc = t2.rfc;

    Select

    t1.campo1,

    t1.campo2,

    t1.rfc

    from

    tabla1 t1

    where

    t1.rfc in ('FAA9905073B9','FCO011107EP2','FRE920401VD8','POL790226L74');

    select

    t2.rfc

    from

    tabla2 t2

    where

    t2.rfc in ('FAA9905073B9','FCO011107EP2','FRE920401VD8','POL790226L74');

  • thanks SSC-Insane

    but already I´ve found the mistake, it is when the information has imported from a txt file, this has a special character, Char(13), Char(10), in this case only we replace these caracters with '' a space null

    Thanks again to all

    🙂

    Angel Miranda Nieto
    DBA Specialist, BI, MCSA SQL Server

  • Angel DBA Mex (5/19/2015)


    thanks SSC-Insane

    but already I´ve found the mistake, it is when the information has imported from a txt file, this has a special character, Char(13), Char(10), in this case only we replace these caracters with '' a space null

    Thanks again to all

    🙂

    People's names are actually above their avatar.

    FYI: CHAR(13) is a Line Feed and CHAR(10) is a Carriage Return. Common in txt files with more than one line. It appears that Lynn used the a Jedi Mind trick to help you with your issue.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply