'How to find a specific row in an index [duplicate]
I am new to MySQL and am not very familiar with it. I am supposed to find a name that starts with b in index, which i do not have the slightest clue of doing.
| id | name | DoB | class | marks | dept_id |
+----+--------------+------------+-------+-------+---------+
| 1 | Data Science | 2006-07-15 | 11 | 100 | 3 |
| 2 | Garry | 2006-08-20 | 11 | 92 | 4 |
| 3 | Jane | 2006-03-22 | 10 | 95 | 2 |
| 4 | Benny | 2005-10-10 | 12 | 74 | 4 |
| 5 | Karen | 2005-01-15 | 12 | 88 | 3 |
| 6 | Camy | 2006-04-18 | 12 | 91 | 2 |
| 7 | Farhan | 2006-09-21 | 11 | 80 | NULL |
| 8 | Shamil | 2005-10-19 | 11 | 90 | 3 |
+----+--------------+------------+-------+-------+---------+
The Table above is (students) And the one Below it is the Index of (students)
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| students | 0 | PRIMARY | 1 | id | A | 6 | NULL | NULL | | BTREE | | | YES | NULL |
| students | 1 | dept_id | 1 | dept_id | A | 3 | NULL | NULL | YES | BTREE | | | YES | NULL |
| students | 1 | name_index | 1 | name | A | 6 | NULL | NULL | | BTREE | | | YES | NULL |
| students | 1 | index_name | 1 | name | A | 6 | NULL | NULL | | BTREE | | | YES | NULL |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
Solution 1:[1]
You have to use SELECT query with LIKE keyword
- The
percentage ( % )wildcard matches any string of zero or more characters. For example,b%matches any string starts with the characterbsuch asBennyandBen.
SELECT * FROM students WHERE name LIKE 'b%';
If you have same name in record which starts from uppercase as well as lowecase then put BINARY keyword after LIKE keyword (Case Sensitive):
SELECT * FROM students WHERE name LIKE BINARY 'b%';
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
