Parsing SQL Data between Tables for a certain Output

  • Hello,

    Extremely new to SQL here - bare with me. I'm looking for some insight on how to accomplish a report I'm trying to make. I need to take data from 1 table, select it but after the selection of data, I want to parse a certain column, run it against another table to change the value to it's matching component with another column. An example below:

    Table 1 - INFO

    [Name] [Age] [IDNumber]

    Joe        30        043827

    Table 2 - MATION

    [ID]          [DESCRIPTION]

    043827   DRIVER LICENSE

    Report output-

    [Name] [Age] [IDNumber]

    Joe        30      DRIVER LICENSE

     

    Any thoughts on how to tackle this, that would be great! Even a spot to start out from.

     

    Thanks,

    -N

  • You should look at JOINs

    SELECT i.Name, i.Age, m.Description AS IDNumber
    FROM [INFO] AS i
    INNER JOIN [MATION] AS m
    ON i.IDNumber = m.ID
  • You can do this using Joins as below:

    --Inner join for exact match between INFO and MATION

    Select i.Name, i.Age, m.Description IDNumber

    From INFO i

    Inner join MATION m on i.IDNumber = m.ID

    --Left Outer join fetches INFO records even if there is no matching record found in MATION

    Select i.Name, i.Age, m.Description IDNumber

    From INFO i

    Left outer join MATION m on i.IDNumber = m.ID

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

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