Introduction to Oracle SQL

104 11

    Queries

    • The SELECT statement is used to query-or retrieve data from- the database. The basic query statement is "SELECT column(s) FROM table;" You specify the which columns you want data from after the keyword SELECT. You can retrieve data from all the columns by placing an asterisk (*) after SELECT. You can also specify arithmetic operators such as +, -, *, and /.

      Conditions can be specified with the WHERE clause. A query with a WHERE has the syntax "SELECT column(s) FROM table WHERE condition;" WHERE clauses can use logical connectives such as and, or and not. They can also use pattern matching and comparison operators such as =, <, and >. They can even contain subqueries.

      Subqueries are separate queries that are contained in the WHERE clauses. They have the syntax "SELECT column(s) FROM table WHERE (SELECT columns FROM table WHERE condition);" The subquery returns a value, or group of values, that are used to create the conditions for the main query.

      Aggregate functions are used within queries to compute a value from a set of values in a column. These functions include COUNT, MAX, MIN, SUM, and AVG. The syntax for the COUNT function is "SELECT COUNT(column) FROM table;" The other aggregate functions have similar syntax.

      The results from queries can be grouped with the GROUP BY clause. The GROUP BY clause has the syntax "SELECT column FROM table WHERE condition GROUP BY group.column;" This clause groups the results by the "group.column" and then returns the results. Used with an aggregate function such as COUNT, you can return the number of records in each "group.column" group.

    Data Modifications

    • Data modification includes inserting, updating and deleting data. The syntax for inserting data into a table is "INSERT INTO table columnA, columnB VALUES valueA, valueB;" For each column listed there must be a corresponding value. You can also write the statement, "INSERT INTO table VALUES valueA, valueB;" with no columns specified. If this is the case, you must have a value for each column in the table, in the order they appear in the table.

      Update statements are used to change the attributes of a record. The syntax for update statements is "Update table columnA=valueA, columnB=expressionB WHERE condition;" Delete statements are used to remove records from the database. The syntax for a delete statement is "DELETE FROM table WHERE condition;" The WHERE clause in update and delete statements can use the same conditions as in the select cause, including subqueries.

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.