none
Query + merging two query for Columns

    Question

  • Hi, 

    I have 2 query , both return one row, with 2 columns , 1st column are common,

    but i want to make one query , where i ll have same records but one query with 3 columns, below are just example

    Select CTGY, Column1 from Table 1        ====CTGY   Column1

                                                                           "A"            32

    Select CTGY, Column2 from Table 1        ====CTGY   Column2

                                                                           "A"            64

    Now one query ?

    Output 

    CTGY Column1 Column2

    "A"       32         64

    Thanks

    A-


    Jumpingboy

    Wednesday, July 31, 2013 1:26 PM

Answers

  • Select a.CTGY, a.Column1, b.column2
    from Table1  a
    Inner join table1 b
    on a.CTGY = b.CTGY
    AND a.name = 'A'
    AND b.name = 'B'



    Sergio Sánchez Arias
    Oaxaca,México
    AYÚDANOS A AYUDARTE

    • Proposed as answer by Naomi NModerator Wednesday, July 31, 2013 3:44 PM
    • Marked as answer by Jumpingboy Wednesday, July 31, 2013 7:15 PM
    Wednesday, July 31, 2013 3:41 PM

All replies

  • Hi:

    I don't understand at all...if you're using the same table in both queries, you need to specify the columns name that you want to get:

    Select CTGY, Column1, Column2 from Table 1 

    But... if you are using two different tables, have you tried this ?

    Select a.CTGY, a.Column1, b.column2
    from Table1  a
    Inner join table2 b
    on a.CTGY = b.CTGY

    Sergio Sánchez Arias
    Oaxaca,México
    AYÚDANOS A AYUDARTE

    Wednesday, July 31, 2013 1:39 PM
  • Why not the below:

    Select CTGY, column1, Column2 from Table 1 


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

    Wednesday, July 31, 2013 1:40 PM
  • I am sorry let me tell you more details

    Query :

    Select CTGY, Column1 from Table 1 Where Name="A"

    ====CTGY   Column1

               "A"            32

    Select CTGY, Column2 from Table 1 Where Name="B"

    ====CTGY   Column2

               "A"            64

    CTGY Column1 Column2

    "A"       32         64

    Let me know if still issues.


    Jumpingboy

    Wednesday, July 31, 2013 2:49 PM
  • Select a.CTGY, a.Column1, b.column2
    from Table1  a
    Inner join table1 b
    on a.CTGY = b.CTGY
    AND a.name = 'A'
    AND b.name = 'B'



    Sergio Sánchez Arias
    Oaxaca,México
    AYÚDANOS A AYUDARTE

    • Proposed as answer by Naomi NModerator Wednesday, July 31, 2013 3:44 PM
    • Marked as answer by Jumpingboy Wednesday, July 31, 2013 7:15 PM
    Wednesday, July 31, 2013 3:41 PM