Select Data

You can retrieve data with ANSI SQL syntax. Here is a simple usage.

For more details, please refer to SELECT page under Data Manipulation.

Syntax:

SELECT * FROM table_name;

Example:

mach> SELECT * FROM mach_log;
DEVICE          TM                              TEMP        

----------------------------------------------------------------

MSG                                                                               

------------------------------------------------------------------------------------

192.168.0.1     NULL                            NULL        
NULL                                                                              
192.168.0.2     2014-06-15 19:50:03 484:382:010 82          
error code = 20, critical warning                                                 
192.168.0.2     2014-06-15 19:50:03 484:382:008 57          
error code = 20                                                                   
192.168.0.1     2014-06-15 19:50:03 484:382:006 99          
error code = 10, critical bug                                                     
192.168.0.1     2014-06-15 19:50:03 484:382:004 55          
error code = 10                                                                   
192.168.0.2     2014-06-15 19:50:03 484:382:002 31        
normal state                                                                      
192.168.0.1     2014-06-15 19:50:03 484:382:000 32          
normal state                                                                      
[7] row(s) selected.
mach
>

The example above is using the input data without index. As you can see below, the last record entered is printed first.

Select with various conditions

Syntax:

SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;

Example;

mach> SELECT * FROM mach_log WHERE device = '192.168.0.1';
DEVICE          TM                              TEMP        
----------------------------------------------------------------
MSG                                                                               
------------------------------------------------------------------------------------
192.168.0.1     NULL                            NULL        
NULL                                                                              
192.168.0.1     2014-06-15 19:50:36 488:663:006 99          
error code = 10, critical bug                                                     
192.168.0.1     2014-06-15 19:50:36 488:663:004 55          
error code = 10                                                                   
192.168.0.1     2014-06-15 19:50:36 488:663:000 32          
normal state                                                                      
[4] row(s) selected.

mach> SELECT * FROM mach_log WHERE device = '192.168.0.1' AND temp > 30 AND temp < 50;
DEVICE          TM                              TEMP        
----------------------------------------------------------------
MSG                                                                               
------------------------------------------------------------------------------------
192.168.0.1     2014-06-15 19:50:36 488:663:000 32          
normal state                                                                      
[1] row(s) selected.

mach> SELECT * FROM mach_log where device > '192.168.0.1';
DEVICE          TM                              TEMP        
----------------------------------------------------------------
MSG                                                                               
------------------------------------------------------------------------------------
192.168.0.2     2014-06-15 19:50:36 488:663:010 82          
error code = 20, critical warning                                                 
192.168.0.2     2014-06-15 19:50:36 488:663:008 57          
error code = 20                                                                   
192.168.0.2     2014-06-15 19:50:36 488:663:002 31          
normal state                                                                      
[3] row(s) selected.

mach> SELECT * FROM mach_log WHERE msg LIKE '%error%';
DEVICE          TM                              TEMP        
----------------------------------------------------------------
MSG                                                                               
------------------------------------------------------------------------------------
192.168.0.2     2014-06-15 19:50:36 488:663:010 82          
error code = 20, critical warning                                                 
192.168.0.2     2014-06-15 19:50:36 488:663:008 57          
error code = 20                                                                   
192.168.0.1     2014-06-15 19:50:36 488:663:006 99          
error code = 10, critical bug                                                     
192.168.0.1     2014-06-15 19:50:36 488:663:004 55          
error code = 10                                                                   
[4] row(s) selected.

results matching ""

    No results matching ""