Conditional query

  • Hi Team,

    I need to use some conditional query :

    Scenario is:

    I have a customer table(customer_number is Primary key) and Contact table , i need to join these to get customer details, but Contact table has got 3 primary keys (customer_number, Line_Number, Owner).

    In contact table i have 3 records for some customer_numbers and 2 records for some and 1 record for some.

    typical Contact Table :

    Customer_number Line_number Owner type Prefix Phonenumber

    123 1 0 011 232323

    123 2 0 F 011 234343

    123 1 1 031 342434

    234 1 0 022 565656

    234 2 0 F 022 565676

    I need to join these two tables to get all the contact details.

    Appreciate your help.

    Thanks

  • What have you tried? Can you show us what you may have attempted?

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:
    http://www.sqlservercentral.com/articles/61537/

  • Yes. Please provide more detail.

    TABLE A

    COLUMN 1 , COLUMN 2, COLUMN 3

    TABLE B

    etc.....

  • sqlquery29 (3/25/2015)


    Hi Team,

    I need to use some conditional query :

    Scenario is:

    I have a customer table(customer_number is Primary key) and Contact table , i need to join these to get customer details, but Contact table has got 3 primary keys (customer_number, Line_Number, Owner).

    In contact table i have 3 records for some customer_numbers and 2 records for some and 1 record for some.

    typical Contact Table :

    Customer_number Line_number Owner type Prefix Phonenumber

    123 1 0 011 232323

    123 2 0 F 011 234343

    123 1 1 031 342434

    234 1 0 022 565656

    234 2 0 F 022 565676

    I need to join these two tables to get all the contact details.

    Appreciate your help.

    Thanks

    A table cannot have 3 primary keys. It might have a composite key of 3 columns, maybe that is what you mean?

    The real problem here is that you have not provided anywhere near enough information for us to be able to help. Please take a few minutes and read the first link in my signature for best practices when posting questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

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

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