- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to select from table where conditions are set for id and name in MySQL?
Let us first create a table −
mysql> create table DemoTable819( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100) ); Query OK, 0 rows affected (0.88 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable819(StudentName) values('Chris'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable819(StudentName) values('Robert'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable819(StudentName) values('Adam'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable819(StudentName) values('Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable819(StudentName) values('Sam'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable819;
This will produce the following output −
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | Chris | | 2 | Robert | | 3 | Adam | | 4 | Mike | | 5 | Sam | +-----------+-------------+ 5 rows in set (0.00 sec)
Following is the query to select from the table where conditions are set for name and id −
mysql> select *from DemoTable819 where StudentName='Robert' and StudentId > 1;
This will produce the following output −
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 2 | Robert | +-----------+-------------+ 1 row in set (0.00 sec)
- Related Articles
- How to select data from a table where the table name has blank spaces in MYSQL?
- Is there an operator in MySQL to implement multiple NOT conditions like WHERE id != 5 AND id != 10 AND id != 15?
- MySQL - SELECT … WHERE id IN (..) order with particular column?
- Can I use two where clauses like “SELECT * FROM table WHERE condition1 and condition2” in MySQL?
- Select from table where value does not exist with MySQL?
- How to select all the records except a row with certain id from a MySQL table?
- How to order and select query with conditions in MySQL?
- MySQL select query to select rows from a table that are not in another table?
- MySQL query to select a random row value (Id and Name) having multiple occurrences (Name)?
- Set an alternative of WHERE clause for each SELECT field in MySQL
- Fetch maximum ID value from the first table and insert to all the IDs in another table with MySQL INSERT INTO select?
- How to SELECT fields from one table and INSERT to another in MySQL?
- Update only a single value from a MySQL table where select from same table ordered in descending order?
- How to select ID column as null in MySQL?
- How to get username using ID from another table in MySQL database?

Advertisements