Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Selecting All Columns or Specific columns

                         

In this section you will be learn how to create database and create a specific columns in MySQL . 

CREATE Statement
The CREATE statement is used to create the table.

Example:
Create the tables:

 

 

mysql> CREATE TABLE Employee (
-> id int unsigned not null auto_increment primary key,
-> f_name varchar(20),
-> l_name varchar(20),
-> age int,
-> salary int,
-> email varchar(60)
-> );
Query OK, 0 rows affected (0.03 sec)

Insert the Data in the table:
The INSERT statement is used the load the data in the table. Keyword are used in this statement are follows :

INSERT - Insert data into the table
INTO - Specified the Table name for inserting the data
VALUES - Data for the columns in the table.

mysql> INSERT INTO Employee (f_name, l_Name, age, salary, email) VALUES ("Deepak", "Kumar", 31, 25000, "Deepak@hotmail.com");
Query OK, 1 row affected (0.00 sec)

MySQL creates the table by the name of Employee with the column along the first row. If you want to only select columns, replace the * with the names of the columns, separated by commas. The select statement follow just like the , SELECT * FROM Employee :

mysql> SELECT * FROM Employee;
+----+-----------+----------+------+--------+---------------+
| id     | f_name     |   l_name   |   age   |  salary   |   email     |
+----+-----------+----------+------+--------+---------------+
| 1     | Deepak     |   kumar    |   31    |  25000  |D@hotmail.com |
+----+-----------+----------+------+--------+---------------+
1 row in set (0.00 sec)

Display the MySQL version

mysql> SELECT VERSION();

For displaying the current date and time

mysql> SELECT NOW( );

Mysql Evaluating Expression
Expressions have operators and terms and they are evaluated to generate values. Expressions contain constants, function calls and references to table columns. These values can be combined using different kinds of operators like comparison or arithmetic operators. Expression terms can be grouped with parentheses.

select concat(last_name, ', ', first_name),
(YEAR(death) - YEAR(birth)) - if(RIGHT(death,5)<RIGHT(birth,5),1,0)
from president
where
birth > '1985-5-5' and death is not null;

When an Expression is encountered MySQL, it evaluates the expression to produce a result.

Writing Expressions
An Writing expression can be as simple as a single constant.
Expressions may use function calls. But some function takes arguments and some does not. And multiple arguments are separated by commas.

 0  Numeric constant
 'abc'  String constant
 '06-11-22'          Date constant

Example:

mysql> select ((25*4)/10)+35;
+----------------+
| ((25*4)/10)+35 |
+----------------+
| 45.00 |
+----------------+
1 row in set (0.00 sec)

CONCAT()
The CONCAT() function uses argument between parenthesis. These can be use columns name or plane text string .

Example

mysql> SELECT CONCAT(f_name, " ", l_name)
from employee_data 
where title = 'Programmer';

+-----------------------------+
| CONCAT(f_name, " ", l_name) |
+-----------------------------+
| Alok Kumar |
| deepak ranjan |
| sushil pal |
| chandan kumar |
+-----------------------------+
4 rows in set (0.00 sec)

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.