Examples For SQL That Help You

Any problem with SQL can be discussed here.
Post Reply
ELMOHTARF
Posts: 356
Joined: Mon Aug 29, 2005 9:57 am
Contact:

Examples For SQL That Help You

Post by ELMOHTARF »

The CHECKS table:

CHECK# PAYEE AMOUNT REMARKS
--------- -------------------- ------ ---------------------
1 Ma Bell 150 Have sons next time
2 Reading R.R. 245.34 Train to Chicago
3 Ma Bell 200.32 Cellular Phone
4 Local Utilities 98 Gas
5 Joes Stale $ Dent 150 Groceries
6 Cash 25 Wild Night Out
7 Joans Gas 25.1 Gas

Your First Query
INPUT:
SQL> select * from checks;
OUTPUT:
queries CHECK# PAYEE AMOUNT REMARKS
------ -------------------- ------- - --------------------

1 Ma Bell 150 Have sons next time
2 Reading R.R. 245.34 Train to Chicago
3 Ma Bell 200.32 Cellular Phone
4 Local Utilities 98 Gas
5 Joes Stale $ Dent 150 Groceries
6 Cash 25 Wild Night Out
7 Joans Gas 25.1 Gas


7 rows selected.
Changing the Order of the Columns
The preceding example of an SQL statement used the * to select all columns from a table, the order of their appearance in the output being determined by the database. To specify the order of the columns, you could type something like:

INPUT:
SQL> SELECT payee, remarks, amount, check# from checks;


Notice that each column name is listed in the SELECT clause. The order in which the columns are listed is the order in which they will appear in the output. Notice both the commas that separate the column names and the space between the final column name and the subsequent clause (in this case FROM). The output would look like this:

OUTPUT:
PAYEE REMARKS AMOUNT CHECK#
-------------------- ------------------ --------- ---------
Ma Bell Have sons next time 150 1
Reading R.R. Train to Chicago 245.34 2
Ma Bell Cellular Phone 200.32 3
Local Utilities Gas 98 4
Joes Stale $ Dent Groceries 150 5
Cash Wild Night Out 25 6
Joans Gas Gas 25.1 7

7 rows selected.


Another way to write the same statement follows.

INPUT:
SELECT payee, remarks, amount, check#
FROM checks;


Notice that the FROM clause has been carried over to the second line. This convention is a matter of personal taste when writing SQL code. The output would look like this:

OUTPUT:
PAYEE REMARKS AMOUNT CHECK#
-------------------- -------------------- --------- --------
Ma Bell Have sons next time 150 1
Reading R.R. Train to Chicago 245.34 2
Ma Bell Cellular Phone 200.32 3
Local Utilities Gas 98 4
Joes Stale $ Dent Groceries 150 5
Cash Wild Night Out 25 6
Joans Gas Gas 25.1 7

7 rows selected

****:The output is identical because only the format of the statement changed. Now that you have established control over the order of the columns, you will be able to specify which columns you want to see.

Selecting Individual Columns
Suppose you do not want to see every column in the database. You used SELECT * to find out what information was available, and now you want to concentrate on the check number and the amount. You type

INPUT:
SQL> SELECT CHECK#, amount from checks;


which returns

OUTPUT:
CHECK# AMOUNT
--------- ---------
1 150
2 245.34
3 200.32
4 98
5 150
6 25
7 25.1


7 rows selected. 8)


With My Best Wishes ::::::: Scorpion :::::::::
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

my opinion, this tutorial is bad stuff. I think, i good know sql syntax and how it works, but then i read your tut, i dont undestand anything :) But keep going, maybe just i dont understand this tut, maybe others will
Image
ELMOHTARF
Posts: 356
Joined: Mon Aug 29, 2005 9:57 am
Contact:

Post by ELMOHTARF »

this words for examle to my table so you crate your table and work this words on it
With My Best Wishes ::::::: Scorpion :::::::::
ELMOHTARF
Posts: 356
Joined: Mon Aug 29, 2005 9:57 am
Contact:

Post by ELMOHTARF »

i sorry for this problem but the site make it because you must keep the number underthe check and this for all
iam relly sorry
With My Best Wishes ::::::: Scorpion :::::::::
Post Reply