Querying multiple tables within a database

  • Hello --

    I am coming up with a query that is meant to reference multiple tables within a single database. Currently there are two tables being queried in this process. The first contains the names of people, while the second lists identification numbers for them.

    What I want to accomplish is to query the two tables, and have the results appear where the names of the people match the identification numbers assigned to each person.

    How would I accomplish this?

    Thanks.

  • Using a JOIN.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Hello --

    Thank-you for your reply. I tried several JOIN statements: INNER, LEFT, RIGHT, FULL OUTER, and while I was able to get a listing of the names, I did not get a listing of their associated identification numbers. The syntax that I used, aside from substituting the JOIN statements is the following:

    SELECT <column name>

    FROM <table 1>

    RIGHT JOIN <table 2>

    ON <table 1 column name>=<table 2 column name>

    I need to have the contents of the table 1 column name side by side with those of the table 2 column shown in the output results.

  • You just need to add more columns to your query.

    It might look something like this:

    SELECT p.name,

    p.anyothercolumns,

    n.idnumber,

    n.anyothercolumns

    FROM People p

    JOIN IDNumbers n ON p.idnumber = n.idnumber

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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