Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5841535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:54:09+00:00 2026-05-22T11:54:09+00:00

Today my question is how would I go about creating a view in a

  • 0

Today my question is how would I go about creating a view in a MySQL database that uses more than two tables?

Here is my query (it works) I am not looking to change my current query, mostly looking for a nice reference with examples on this topic.

CREATE OR REPLACE VIEW vw_itemsPurchased AS
SELECT `tbl_buyers`.`fldPrimaryKey` as fldFKeyBuyer, `tbl_buyers`.`fldEmail` as fldBuyerEmail, `tbl_buyers`.`fldAddressStreet`, `tbl_buyers`.`fldAddressCity`, `tbl_buyers`.`fldAddressState`, `tbl_buyers`.`fldAddressZip`, `tbl_buyers`.`fldAddressCountry`, `fldPaymentCurrency`, `fldPaymentGross`, `fldPaymentStatus`, `fldReceiverEmail`, `fldTransactionId`
FROM `tbl_transactions` INNER JOIN `tbl_buyers`
ON `tbl_transactions`.`fldFKeyBuyer` = `tbl_buyers`.`fldPrimaryKey`

Thanks for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:54:09+00:00Added an answer on May 22, 2026 at 11:54 am

    To use more than two tables, you simply continue adding JOIN statements to connect foreign keys. Adapting your code to add an imaginary third table tbl_products might look like this:

    CREATE OR REPLACE VIEW vw_itemsPurchased AS (
      SELECT 
       tbl_buyers.fldPrimaryKey as fldFKeyBuyer, 
       tbl_buyers.fldEmail as fldBuyerEmail, 
       tbl_buyers.fldAddressStreet, 
       tbl_buyers.fldAddressCity, 
       tbl_buyers.fldAddressState, 
       tbl_buyers.fldAddressZip, 
       tbl_buyers.fldAddressCountry, 
       fldPaymentCurrency, fldPaymentGross, 
       fldPaymentStatus, 
       fldReceiverEmail,
       fldTransactionId,
       tbl_tproducts.prodid
     FROM 
       tbl_transactions 
        INNER JOIN tbl_buyers ON tbl_transactions.fldFKeyBuyer = tbl_buyers.fldP
        -- Just add more JOINs like the first one..
        JOIN tbl_products ON tbl_products.prodid = tbl_transactions.prodid
    

    In the above method, the first and second tables relate, and the first and third tables relate. If you have to relate table1->table2 and table2->table3, list multiple tables in the FROM and relate them in the WHERE. The below is just for illustration and doesn’t make much sense, as you probably wouldn’t have a customer id in the same table as a product price.

    SELECT
      t1.productid,
      t2.price,
      t3.custid
    FROM t1, t2, t3
    WHERE 
      -- Relationships are defined here...
      t1.productid = t2.productid 
      AND t2.custid = t3.custid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Earlier today I asked a question about environ , and one of the more
Here's a quick question I've been banging my head against today. I'm trying to
This is a follow-up to another question I asked earlier today. I am creating
Read this question today about safe and unsafe code I then read about it
Hi I asked a question today about How to insert different types of objects
This may be a very noobie question, but in today's world of web app
Earlier today a question was asked regarding input validation strategies in web apps .
I was going to Ask a Question earlier today when I was presented to
Today I was listening to the Hanselminutes show about .NET 3.5 SP1...What's inside ,
Today I discovered that my fresh installation of Apache HTTP Server is able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.