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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:55:38+00:00 2026-05-23T20:55:38+00:00

I want to return field name from a database table where id = 4.

  • 0

I want to return field name from a database table where id = 4. Which query is easier for MYSQL to process.

SELECT name, id FROM table WHERE id = 4

or

SELECT name FROM table WHERE id = 4

I suppose I’m asking if it’s good practice to put the field from the WHERE statement in SELECT as well even if I won’t return it in php.

  • 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-23T20:55:38+00:00Added an answer on May 23, 2026 at 8:55 pm
    SELECT name, id FROM table WHERE id = 4
    

    would also have the id in the result from mysql and it would make very little difference to the data as it is only a numeral however if you were to do this where you were selecting something else such as SELECT name, id FROM table WHERE name = "ron" would definitely a bad practice as more data is being transferred from the database server as you already know the name “ron” and since it is not unique it could have more than one rows.

    mysql> explain select id,name from admin_users where id = 1;
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    | id | select_type | table       | type  | possible_keys | key     | key_len | ref   | rows | Extra |
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    |  1 | SIMPLE      | admin_users | const | PRIMARY       | PRIMARY | 4       | const |    1 |       |
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    1 row in set (0.00 sec)
    
    mysql> explain select name from admin_users where id = 1;
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    | id | select_type | table       | type  | possible_keys | key     | key_len | ref   | rows | Extra |
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    |  1 | SIMPLE      | admin_users | const | PRIMARY       | PRIMARY | 4       | const |    1 |       |
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    1 row in set (0.00 sec)
    

    compared to

    mysql> explain select id,name from admin_users where name = 'ron';
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    | id | select_type | table       | type  | possible_keys | key     | key_len | ref   | rows | Extra |
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    |  1 | SIMPLE      | admin_users | const | PRIMARY       | PRIMARY | 4       | const |    1 |       |
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    123 row in set (0.11 sec)
    
    mysql> explain select name from admin_users where name = 'ron';
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    | id | select_type | table       | type  | possible_keys | key     | key_len | ref   | rows | Extra |
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    |  1 | SIMPLE      | admin_users | const | PRIMARY       | PRIMARY | 4       | const |    1 |       |
    +----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
    123 row in set (0.05 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to return a private field from a remoted object but i get
How do I specify the parent query field from within a subquery in MySQL?
I have a database table which contains an ID column and a Name column.
I want to return a set of values from function till the point they
my problem is that, i want to save class object java.lang.reflect.Field into database using
That is, with a prepared statement like: select col1,...coln from table where col3 =
I am trying to export data from my MySQL database to multiple CSV files
I have a database schema like this picture: I want to write a query
I want to do a join accross a MS-SQL and MySql database. The MS-SQL
Background: I'm pulling all of the field names from a database into an array

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.