locked
Query join from two table, display RRS feed

  • Question

  • User-27405682 posted

    Hi please advice on the table below to help me on this simple query

    I want to display the pcbaNo that join with the serial_1. 

    Table 1 

    table image 1

    Table 2

    table image 2

    Result going to achieve

    pcbaNo, serailNo_1,pcbaNo,serialNo_2,weight,empno,datecreated

    EDU0007,1651PJ0014,EDU0016,1651UJ0015,4,08264,2018-09-27

    Thursday, September 27, 2018 3:35 AM

All replies

  • User283571144 posted

    Hi FookWah,

    Accoridng to your description, I suggest you could use sql query inner join to achieve your requirement.

    More details, you could refer to below sql query.

    pcbaTable:

    CREATE TABLE [dbo].[pcbaTable]
    (
    	[pcbaNo] nvarchar(100) NOT NULL PRIMARY KEY, 
        [sericalNo] NCHAR(10) NULL, 
        [dateCreated] DATETIME NULL
    )
    

    SericalTable

    CREATE TABLE [dbo].[SericalTable]
    (
    	[Id] INT NOT NULL PRIMARY KEY, 
        [serialNo_1] NCHAR(10) NULL, 
        [serialNo_2] NCHAR(10) NULL, 
        [weight] INT NULL, 
        [emp_no] NCHAR(10) NULL, 
        [dateCreated] DATETIME NULL
    )
    

    Sql query:

    SELECT a.pcbaNo,b.serialNo_1, b.serialNo_2, b.weight, b.emp_no, b.dateCreated FROM pcbatable AS a INNER JOIN sericaltable AS b ON a.sericalNo = b.serialNo_1

    Result:

    Best Regards,

    Brando

    Thursday, September 27, 2018 5:59 AM
  • User-27405682 posted

    Hi Brando,

    Thanks you for the reply.

    The result i want to achieve are 

    pcbaNo ,serial no from other table, pcbaNo and serial no from other table

    both serial no can get from sericalTable

    EDU007,1651PJ0014,EDU0016,1651UJ0015,weight

    Friday, September 28, 2018 3:49 AM
  • User283571144 posted

    Hi FookWah,

    I still couldn't understand your issue clearly.

    Could you please tell me which column you want to get from which table?

    For exmaple:

    pcbaNo ,serial From TableA

    pcbaNo and serial From TableB

    Requirement: I want to search both tableA and B contains same pcbaNo's record.

    Best Regards,

    Brando

    Tuesday, October 2, 2018 6:12 AM