MySQL select first row

In this article we are going to discuss how to SELECT  first row of MySQL table.

Here we are going to create a table ‘sales_team_emails’ which we will be using in our article,

CREATE TABLE sales_team_emails (
    sales_person_id INT AUTO_INCREMENT,
    sales_person_name VARCHAR(255),
    sales_person_email VARCHAR(255),
    PRIMARY KEY (sales_person_id)
);

Insert values in table;

INSERT INTO sales_team_emails (sales_person_name,sales_person_email) 
 VALUES("Shikha","shikha@managementbliss.com"),
 ("Rahul","Rahul.Abey@me.com"),
 ("Varun","Varun.Loud@me.com"),
 ("Aarav","Aarav@managementbliss.com"), 
 ("Ishan","Ishan@mine.com"),
  ("Aditi","Aditi.Sun@me.com"),
 ("Ram","Ram.Thomas@mine.com"),
 ("Aditi Sharma","aditi@managementbliss.com"),
 ("Etiv","Etiv.Abey@me.com"),
 ("Ishu","Ishu.Freebird@me.com"),
 ("Siya","Siya.com");

Output:

Select first row in mysql

Example 1:

Now we are going to select  first record of a table using below query,

SELECT * FROM sales_team_emails LIMIT 1;

You can see that here we have used LIMIT because we want to select only first row.We use LIMIT whenever we want some restrictions.

Output:

Select-first-row-in-mysql-table

In output you can see that we have got first row value from table ‘sales_team_emails‘.

Example2:

Now we are going to get record of a row which user want like,SELECT first record  the table sales_team_emails where sales_person_name is Ram.

SELECT 
    sales_person_id, sales_person_email
FROM
    sales_team_emails
WHERE
    sales_person_name = 'Ram'
LIMIT 1;

Output:

Select first row in mysql table 2
Here you can see that we have got desired output like this we can get any row value.

Conclusion:

In this article we have discussed how to SELECT  first row of MySQL table.Thank You!