Library tutorials & articles
SQL In Simple English
- Introduction
- Lets get started
- Basic SELECT statements
- Inserting, Deleting & Updating
- More Advanced SQL
- Show me more!
Basic SELECT statements
What are you going to discuss now?
Now you will learn basic SQL statements such as SELECT,
INSERT, UPDATE and
DELETE.
For all the examples in this article we would be using a sample database table
which is shown below
Table Name : people
| lastname | firstname | age | address | city |
|
Pai
|
Kiran
|
|
Mahavir Nagar
|
Mumbai
|
|
Hunter
|
Jason
|
|
Oak Street
|
San Jose
|
|
Kanetkar
|
Yashwant
|
|
Rajabhai Street
|
Nagpur
|
What is SELECT statement? How do I use it?
The SELECT statement lets you select a set of values
from a table in a database. The values selected from the database table would
depend on the various conditions that are specified in the SQL query. Here are
some ways to use the SELECT statement. I have listed the SQL statements and the
respective results that you would obtain if you would execute those queries.SELECT lastname,firstname FROM people
Would return a recordset with 3 records. Each record would have 2 values.
The first record would have 2 values 'Pai' and 'Kiran'. Whereas the second record
would have 2 values 'Hunter' and 'Jason'.SELECT * FROM people WHERE firstname='Jason'Would return a recordset with 1 record. The record would have 5 values
in that, namely 'Hunter' , 'Jason' , '41' , 'Oak Street' and 'San Jose'.SELECT * FROM people WHERE age>25Would return a recordset with 2 records.
Note : That whenever you are comparing a varchar the value should be enclosed
in single inverted commas ( ' ). Whereas when you compare an integer the value
need not be enclosed in single inverted commas.
How can I compare a part of the name rather than the entire name?SELECT * FROM people WHERE firstname LIKE '%an%'Would return a recordset with 2 records. This statement would return 2
records since the sequence 'an' occurs
in 2 firstname values, 'Kiran' and 'Yashwant'.
Can I use Boolean operators such as AND or OR to make complex queries?
Good news!! Yes you can.. Actually as a matter of fact, once you start developing
professional database applications you would almost always use such Boolean operators
to make effective queries.SELECT address FROM people WHERE (firstname='Kiran' OR
city='Nagpur') AND age>30
Would return a recordset consisting of 1 record with 1 value only. Since AND
condition specifies that the firstname of the person could be 'Kiran'
or his city could be 'Nagpur' , BUT that person has to be over the age
of 30. The recordset would have only 1 value in it : 'Rajabhai Street'.
Related articles
Related discussion
-
How to receive data in web server sending from GPRS modem
by AshokSingh (1 replies)
-
how to make smtp in vb.net
by konikula (1 replies)
-
copying access DB to SQL DB
by konikula (1 replies)
-
MS Access in 3 different language
by konikula (2 replies)
-
How do I update a table that has an ID from a table that does not have an ID but has a PIDM?
by konikula (1 replies)
Related podcasts
-
Stack Overflow: Podcast #31
This is the thirty-first episode of the StackOverflow podcast, where Joel and Jeff discuss.. stuff! Based on some comments from Podcast #30, we now know that “Learning about NP-Completeness from Jeff is like learning about irony from Alanis Morissette”. It’s funny b...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Oracle Apps Database Administrator - Standplaats: Utrecht
in AMSTERDAM (€50K-€90K per annum) -
Business Analist BI/Datawarehousing
in Amsterdam (€50K-€90K per annum) -
Oracle Ontwikkelaar
in Amsterdam (€50K-€90K per annum)
Events coming up
-
Jun
16
Code Generation 2009
Cambridge, United Kingdom
A developer event with a practical focus on helping people get to grips with code generation tools and technologies.
Hi I would first like to say your site has been really helpful to me.
When using ASP to display database information in a web page you might use
[courier new]
Set adoConnect = Server.CreateObject("ADODB.Connection")
adoConnect.Open "Reports"
Set onIndex = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM index WHERE number=10"
onIndex.Open strSQL, adoConnect
[/courier new]
Then if you wanted to display the recordset you could use
[courier new]
<% onIndex=("Number") %>
[/courier new]
but what I can't work out is if your select statement uses COUNT how do you display the result
[courier new]
Set adoConnect = Server.CreateObject("ADODB.Connection")
adoConnect.Open "Reports"
Set onIndex = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT COUNT(*) FROM index WHERE number=10"
onIndex.Open strSQL, adoConnect
[/courier new]
sorry probably it has been too long and may be you've got the answer but try this
select * from table where date> #2/2/1979#
hi..
check this ... should work
select * from tablename where DateOfBirth<TODATE('10/9/1976','mm/dd/yyyy')
try using TO_DATE with the date you want.. i have used this before in this manner..
hope it helps
bye
Thanks, very helpful.
What about dates though? What is the code for finding dates using the SELECT statement eg 'SELECT from * WHERE DateOfBirth < 10/9/76 10:01:10', I can't get it to work.
This thread is for discussions of SQL In Simple English.