- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 structure some data in a MySQL database for easier retrieval?
You can use FIND_IN_SET to structure some data in a database for easier retrieval. Let us first create a table −
mysql> create table DemoTable ( CountryName SET('US','UK','AUS') ); Query OK, 0 rows affected (0.49 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('US'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('UK'); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+ | CountryName | +-------------+ | US | | UK | +-------------+ 2 rows in set (0.00 sec)
Following is the query to fetch a value −
mysql> select *from DemoTable where find_in_set('UK',CountryName) > 0;
This will produce the following output −
+-------------+ | CountryName | +-------------+ | UK | +-------------+ 1 row in set (0.00 sec)
Advertisements