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 6226917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:07:15+00:00 2026-05-24T09:07:15+00:00

I have a few tables in a MySQL database similar to this setup: major

  • 0

I have a few tables in a MySQL database similar to this setup:

major table

---------------------
| id | name         |
|-------------------|
|  0 | Architecture |
|  1 | Biology      |
|  2 | Chemistry    |
---------------------

college table

----------------------
| id | name          |
|--------------------|
|  0 | Georgia Tech  |
|  1 | Virginia Tech |
|  2 | Cal Tech      |
----------------------

users table

----------------------------------------------
| id | name          | major_id | college_id |
|--------------------------------------------|
|  0 | John Smith    |       2  |         0  |
|  1 | Kevin Lee     |       2  |         1  |
|  2 | Matt Anderson |       0  |         2  |
----------------------------------------------

Using PHP, I want to get all the information for a user using a query similar to this:

SELECT * FROM users WHERE name=`$user`

Is there someway for MySQL to automatically link the “major_id” and “college_id” columns to the “major” and “college” tables in a way where the query above would return the appropriate values?

If it is not possible with a single query, would multiple queries slow down performance considerably?

  • 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-24T09:07:16+00:00Added an answer on May 24, 2026 at 9:07 am
    SELECT * FROM users WHERE name='$user'
    

    This query (yours has back ticks around $user, back ticks are for column names, use double/single quotes) will only return values from the users table. You can’t make MySQL “automagically” construct your joins. You have to do it explicitly, otherwise, how would you get information only from the users table if you wanted to? Use a JOIN like this:

    SELECT users.name AS Username, college.name AS College, major.name AS Major
    FROM users
    INNER JOIN college ON users.college_id = college.id
    INNER JOIN major ON users.major_id = major.id 
    

    Limit the retrieved columns by only selecting the ones you really need. So instead of the asterisk, write users.name etc.

    The JOIN syntax is described in the MySQL Docs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a legacy mysql database and there's this table which has a few
So I have a database with a few tables. The first table contains the
I have a MySQL database that has a few very simple tables. I would
I currently use enums as TINYINTs in MySQL database. My tables have a few
I currently have a few tables in my MySQL database where I declare the
I have a MySQL 5.0 database with a few tables containing over 50M rows.
I have a few tables that have similar fields but not exactly the same.
I have a MS Access database with few tables and a form. When more
This is not an issue with a few tables, but when I have a
So the scenario is this: I have a mySQL database on a local server

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.