Difference between revisions of "SELECT"

From SQLZOO
Jump to: navigation, search
(Blanked the page)
 
(16 intermediate revisions by 7 users not shown)
Line 1: Line 1:
A SELECT statement gets data from a table. Each table contains rows and columns - you can SELECT some columns and ignore others
 
*The column names on the select line control which columns you get
 
*The FROM clause controls which table you access
 
<div class=params>schema:scott</div>
 
The table <code>EMP</code> shows the year and the city hosting the Olympic Games.
 
<table border='1'>
 
<caption>EMP</caption>
 
<tr> <th>ENAME</th> <th>JOB</th> <th>SAL</th></tr>
 
<tr> <td align='right'>SMITH</td> <td>CLERK</td>  <td>800</td></tr>
 
<tr> <td align='right'>ALLEN</td> <td>SALESMAN</td> <td>1600</td></tr>
 
<tr> <td align='right'>WARD</td> <td>SALESMAN</td><td>1250</td> </tr>
 
<tr> <td align='right'>MARTIN</td> <td>SALESMAN</td><td>1250</td> </tr>
 
</table>
 
<div class=qu>
 
The SELECT statement returns results from a <i>table</i>.
 
In this example the table is <code>EMP</code> and the columns are
 
<code>ENAME</code> and <code>JOB</code>.
 
<div class=tidy>
 
DROP TABLE EMP;
 
</div>
 
<div class=setup>
 
CREATE TABLE EMP(ENAME INT, JOB VARCHAR(20),SAL INT);
 
INSERT INTO EMP(ENAME,JOB, SAL) VALUES ('SMITH','CLERK',800);
 
INSERT INTO EMP(ENAME,JOB, SAL) VALUES ('ALLEN',SALESMAN,1600);
 
INSERT INTO EMP(ENAME,JOB, SAL) VALUES ('WARD',SALESMAN,1250);
 
INSERT INTO EMP(ENAME,JOB, SAL) VALUES ('MARTIN',SALESMAN,1250);
 
</div>
 
<div class=def>
 
SELECT ENAME, JOB FROM games
 
</div>
 
</div>
 
  
===See also:===
 
*[[SELECT_basics | SELECT Tutorial]] - practice using the SELECT command
 
*[[SELECT_.._WHERE  |SELECT ... WHERE]] - the WHERE clause allows you to get some rows but not others
 

Latest revision as of 04:00, 17 April 2014

Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense