Sie sind auf Seite 1von 2

13/04/13

SQL SELECT Statement

Select Language HOME HTML C SS JAVASC RIPT JQUERY XML ASP.NET PHP SQL MORE...
R EFER ENC ES | EXAMPLES | FO R UM | ABO UT

SHARE THIS PAGE

Suka

54rb

SQL Basic
SQL HOME SQL Intro SQL Syntax SQL Select SQL Distinct SQL Where SQL And & Or SQL Order By SQL Insert SQL Update SQL Delete

SQL SELECT Statement


Previous
This chapter will explain the SELECT and the SELECT * statements.

Next Chapter

The SQL SELECT Statement


The SELECT statement is used to select data from a database. The result is stored in a result table, called the result-set.

SQL SELECT Syntax


S E L E C Tc o l u m n _ n a m e ( s ) F R O Mt a b l e _ n a m e
and

SQL Demo
SQL Try It

SQL Advanced
SQL Top SQL Like SQL Wildcards SQL In SQL Between SQL Alias SQL Joins SQL Inner Join SQL Left Join SQL Right Join SQL Full Join SQL Union SQL Select Into SQL Create DB SQL Create Table SQL Constraints SQL Not Null SQL Unique SQL Primary Key SQL Foreign Key SQL Check SQL Default SQL Create Index SQL Drop SQL Alter SQL Increment SQL Views SQL Dates SQL Nulls SQL isnull() SQL Data Types

S E L E C T*F R O Mt a b l e _ n a m e
Note: SQL is not case sensitive. SELECT is the same as select.

An SQL SELECT Example


The "Persons" table: P_Id 1 2 3 LastName Hansen Svendson Pettersen FirstName Ola Tove Kari Address Timoteivn 10 Borgvn 23 Storgt 20 City Sandnes Sandnes Stavanger

Now we want to select the content of the columns named "LastName" and "FirstName" from the table above. We use the following SELECT statement:

S E L E C TL a s t N a m e , F i r s t N a m eF R O MP e r s o n s
The result-set will look like this: LastName Hansen Svendson Pettersen FirstName Ola Tove Kari

SELECT * Example
Now we want to select all the columns from the "Persons" table. We use the following SELECT statement:

S E L E C T*F R O MP e r s o n s
Tip: The asterisk (*) is a quick way of selecting all columns! The result-set will look like this: P_Id 1 2 3 LastName Hansen Svendson Pettersen FirstName Ola Tove Kari Address Timoteivn 10 Borgvn 23 Storgt 20 City Sandnes Sandnes Stavanger

SQL Functions
SQL Functions SQL avg() SQL count() SQL first() SQL last() SQL max() SQL min() SQL sum() SQL Group By SQL Having SQL ucase() SQL lcase() SQL mid() SQL len() SQL round()

Navigation in a Result-set
Most database software systems allow navigation in the result-set with programming functions, like: Move-ToFirst-Record, Get-Record-Content, Move-To-Next-Record, etc. Programming functions like these are not a part of this tutorial. To learn about accessing data with function calls, please visit our ADO tutorial or our PHP tutorial.

w3schools.com/sql/sql_select.asp

1/2

13/04/13
SQL now() SQL format() SQL Quick Ref SQL Hosting SQL Summary

SQL SELECT Statement

Previous

Next Chapter

SQL Quiz
SQL Quiz

Top 10 Tutorials
HTML Tutorial HTML5 Tutorial C SS Tutorial C SS3 Tutorial JavaScript Tutorial jQuery Tutorial SQL Tutorial PHP Tutorial ASP.NET Tutorial XML Tutorial

Top 10 References
HTML/HTML5 Reference C SS 1,2,3 Reference C SS 3 Browser Support JavaScript HTML DOM XML DOM PHP Reference jQuery Reference ASP.NET Reference HTML C olors

Examples
HTML Examples C SS Examples XML Examples JavaScript Examples HTML DOM Examples XML DOM Examples AJAX Examples ASP.NET Examples Razor Examples ASP Examples SVG Examples

Quizzes
HTML Quiz HTML5 Quiz XHTML Quiz C SS Quiz JavaScript Quiz jQuery Quiz XML Quiz ASP Quiz PHP Quiz SQL Quiz

Color Picker

Statistics
Browser Statistics Browser OS Browser Display

RE P O RT E RRO R

HO ME

TO P

P RI N T

FO RU M

A BO U T

A D V E RT I SE WI T H U S

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use and privacy policy. C opyright 1999-2013 by Refsnes Data. All Rights Reserved.

w3schools.com/sql/sql_select.asp

2/2

Das könnte Ihnen auch gefallen