PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Introduction to SQL
Your Ad Here

Introduction to SQL


Where

We can use the WHERE statement to be selective.

SELECT name FROM people WHERE gender = 'male'

I'm sure you can understand that. Select the name column from the table people where the gender column is equal to male. What would this select?

Bob, Joe, Jeff

We could select every column from the table where the gender is female.

SELECT * FROM people WHERE gender = 'female'

That would select all the information from the table where the gender contains "female". Simple enough? SQL speaks for itself, it does what it says, it isn't difficult at all.

Insert

We can insert new rows into the database if we wish, here's the structure.

INSERT INTO people (id, name, gender, location, age) VALUES ('6', 'Fred', 'male', 'Chile', '25')

That statement would insert a new row. In the first brackets we list the columns in which we want to enter a value (all in this case), in the second set of brackets we enter the value. The order of the values listed in the first bracket must match the order of the values to insert in the second brackets. So now we have a new row.

Table: People

ID NAME GENDER LOCATION AGE
1 Bob Male UK 31
2 Jill Female USA 24
3 Joe Male Germany 19
4 Jeff Male France 46
5 Sue Female UK 29
6 Fred Male Chile 25

Delete

Maybe we want to delete a row from the table, or delete multiple rows, here's how we do it.

DELETE FROM people WHERE name = 'Joe'

This statement would delete any row where the name is Joe, read the query, it does what it says. So now we would have:

Table: People

ID NAME GENDER LOCATION AGE
1 Bob Male UK 31
2 Jill Female USA 24
4 Jeff Male France 46
5 Sue Female UK 29
6 Fred Male Chile 25

We could delete all the males from the table.

DELETE FROM people WHERE gender = 'male'

Now we would have:

Table: People

ID NAME GENDER LOCATION AGE
2 Jill Female USA 24
5 Sue Female UK 29

It really does speak for itself, you just need to learn the statements.


Author's URL: allsyntax.com
Thank you for voting. Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "Introduction to SQL"

Only registered users can write comment

No comments yet...