Skip to content

Instantly share code, notes, and snippets.

@krishnaiitd
Last active April 28, 2016 23:59
Show Gist options
  • Save krishnaiitd/6373ad1281f76bb4ebbe32ef8946c73b to your computer and use it in GitHub Desktop.
Save krishnaiitd/6373ad1281f76bb4ebbe32ef8946c73b to your computer and use it in GitHub Desktop.
Test user table values
mysql> select * from testuser;
+------+--------------+
| id | code |
+------+--------------+
| 1 | 232 |
| 2 | adfksa121dfk |
| 3 | 12sdf |
| 4 | dasd231 |
| 5 | 897 |
+------+--------------+
5 rows in set (0.00 sec)
mysql> show create table testuser;
+----------+---------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------+---------------------------------------------------------------------------------------------------------------------------------+
| testuser | CREATE TABLE `testuser` (
`id` int(11) DEFAULT NULL,
`code` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+----------+---------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
h1.http://stackoverflow.com/questions/36838717/how-to-check-that-a-column-values-has-string-or-digits-values-in-mysql
Reply from: http://stackoverflow.com/users/5933698/jothi
mysql> SELECT * FROM testuser;
+------+--------------+
| id | code |
+------+--------------+
| 1 | 232 |
| 2 | adfksa121dfk |
| 3 | 12sdf |
| 4 | dasd231 |
| 5 | 897 |
+------+--------------+
5 rows in set (0.00 sec)
mysql> SELECT * FROM testuser where code NOT REGEXP '^[0-9]+$';
+------+--------------+
| id | code |
+------+--------------+
| 2 | adfksa121dfk |
| 3 | 12sdf |
| 4 | dasd231 |
+------+--------------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM testuser where code REGEXP '^[0-9]+$';
+------+------+
| id | code |
+------+------+
| 1 | 232 |
| 5 | 897 |
+------+------+
2 rows in set (0.00 sec)
mysql>
Reply from: http://stackoverflow.com/users/5076266/thilina-sampath
mysql> SELECT * FROM testuser;
+------+--------------+
| id | code |
+------+--------------+
| 1 | 232 |
| 2 | adfksa121dfk |
| 3 | 12sdf |
| 4 | dasd231 |
| 5 | 897 |
+------+--------------+
5 rows in set (0.00 sec)
mysql> select id,code from testuser where code REGEXP '^[0-9]*';
+------+--------------+
| id | code |
+------+--------------+
| 1 | 232 |
| 2 | adfksa121dfk |
| 3 | 12sdf |
| 4 | dasd231 |
| 5 | 897 |
+------+--------------+
5 rows in set (0.00 sec)
mysql> select id,code from testuser where code like '%[^0-9]*%'
-> ;
Empty set (0.00 sec)
mysql>
Reply from: http://stackoverflow.com/users/2978840/jordan
mysql> SELECT * FROM testuser;
+------+--------------+
| id | code |
+------+--------------+
| 1 | 232 |
| 2 | adfksa121dfk |
| 3 | 12sdf |
| 4 | dasd231 |
| 5 | 897 |
+------+--------------+
5 rows in set (0.00 sec)
mysql> SELECT id,code
-> FROM table_name
-> WHERE code REGEXP '^[0-9]+$';
ERROR 1146 (42S02): Table 'test.table_name' doesn't exist
mysql> SELECT id,code FROM testuser WHERE code REGEXP '^[0-9]+$';
+------+------+
| id | code |
+------+------+
| 1 | 232 |
| 5 | 897 |
+------+------+
2 rows in set (0.00 sec)
mysql> SELECT id,code FROM testuser WHERE code REGEXP '^[a-zA-Z]+$';
Empty set (0.00 sec)
mysql>
Reply from: http://stackoverflow.com/users/1087195/lolka-bolka
mysql> SELECT * FROM testuser WHERE `code` REGEXP '[0-9]';
+------+--------------+
| id | code |
+------+--------------+
| 1 | 232 |
| 2 | adfksa121dfk |
| 3 | 12sdf |
| 4 | dasd231 |
| 5 | 897 |
+------+--------------+
5 rows in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment