SQL : Select Query
Introduction:
The SELECT query/statement allows to retrieve records from one or more tables in database.
The syntax for the SELECT statement is:
SELECT [ columns] FROM [tables] WHERE [predicates];
Example #1
Let's take a look at how to select all fields from a table.
SELECT *FROM ebooks WHERE author = 'Azhar';
In our example, we've used * to signify that we wish to view all fields from the ebooks table whose author is 'Azhar'.
Example #2
You can also choose to select individual fields as opposed to all fields in the table.
For example:
SELECT name, ISBN FROM ebooks WHERE ebookid > 1000;
This select statement would return all ebooks' name and their respective ISBN values from the ebooks table where the ebookid value is greater than 1000.
Example #3
You can also use the select statement to retrieve fields from multiple tables.
SELECT category.name,ebooks.ebookid, ebooks.name FROM category,ebooks WHERE category.categoryid=ebooks.categoryid;
The result set would display category name and and ebooks lies in the category
The SELECT query/statement allows to retrieve records from one or more tables in database.
The syntax for the SELECT statement is:
SELECT [ columns] FROM [tables] WHERE [predicates];
Example #1
Let's take a look at how to select all fields from a table.
SELECT *FROM ebooks WHERE author = 'Azhar';
In our example, we've used * to signify that we wish to view all fields from the ebooks table whose author is 'Azhar'.
Example #2
You can also choose to select individual fields as opposed to all fields in the table.
For example:
SELECT name, ISBN FROM ebooks WHERE ebookid > 1000;
This select statement would return all ebooks' name and their respective ISBN values from the ebooks table where the ebookid value is greater than 1000.
Example #3
You can also use the select statement to retrieve fields from multiple tables.
SELECT category.name,ebooks.ebookid, ebooks.name FROM category,ebooks WHERE category.categoryid=ebooks.categoryid;
The result set would display category name and and ebooks lies in the category
Comments
Post a Comment