MYSQL: Grabbing data from two tables

Posted on 2012-09-14
Medium Priority
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

Accepted Solution

WotanAU earned 2000 total points
ID: 38397844
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.

Author Closing Comment

ID: 38398049

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this article, we’ll look at how to deploy ProxySQL.
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

850 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