MYSQL: Grabbing data from two tables

Posted on 2012-09-14
Last Modified: 2012-09-14
A query to grab specific data from two tables.

If I have one table with user ID and the user name,

Then I have a second table with a reference to the user ID, and some other information, lets say company name and company URL. How could I run a mysql query to get all the information needed.

What I'd want is the user name, the company name, and the url for example. So Username,CompanyName,Url grabbed from MYSQL within one query from both tables.

How is this possible? Thank you!
Question by:Valleriani
    LVL 2

    Accepted Solution

    Easy. All you need is an Inner Join:
    SELECT Table1.Username, Table2.CompanyName, Table2.CompanyURL
    FROM Table1 INNER JOIN Table2 ON Table1.UserID = Table2.UserID;

    Open in new window

    Should take care of that.
    LVL 7

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Creating and Managing Databases with phpMyAdmin in cPanel.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now