What the use of SQL Alias In sql query?
What the use of SQL Alias In sql query?
SQL Alias is the basically use for the make a easier to the query, I mean when you have a very long or complex table names or column names. Then we can use this function like :
Assume we have a table called \"Employer\" and another table called \"Product_Orders\". We will give the table aliases of \"e\' an \"po\" respectively. Now we would like to list all the orders that \"Modi groups\" is responsible for :
SELECT Statement With Alias:SELECT po.OrderID, e.LastName, e.FirstName FROM Employer AS e ,Product_Orders AS p WHERE p.LastName=\'Modi\' WHERE p.FirstName=\'Groups\'
Now SELECT Statement with out Alias :SELECT Product_Orders.OrderID, Employer.LastName, Employer.FirstName FROM Employer, Product_Orders WHERE Employer.LastName=\'Modi\' WHERE Emloyer.FirstName=\'Groups\';
Now we can see that with alias query is so easy .
More interview questions and answers |
---|
HAVING cause is using for the show groups satisfying a criteria, |
IN clause uses when we would like to get results if a field has any of the given value : |
To count number of records in the table .For example we want to know How many employers are in the table : |
How can I retrieve a row with columns having a particular pattern? |
To retrieve a row with columns having a particular pattern. For the Example pay of all those employees whose name starts with A : |
To retrieve selected columns of a particular row: |
When i would like to insert the data then we use to the \'INSERT INTO\' command followed by table name and values to be inserted. |
For the create Table firstly we use \'CREATE TABLE\' command with name and data-type of each table field. We can also specify PRIMARY KEY and any other constraint like NOT NULL. |
To retrieve all columns of a particular row we can use where clause in sql |
To retrieve few columns of all rows: |
We have a two ways for updating the table, Which is shown here : |
How can i short list to the table with resect to the column? |
When we would like to get the sorted listed of the data with respect to any columns , Then we can use ORDER BY clause . |
When we would like to see our table then we Use SELECT command to retrieve the data. |
How can I Use AND/OR in WHERE clause to retrieve data based on multiple condition? |
Use AND/OR in WHERE clause to retrieve data based on multiple condition. |
We can also delete all records using TRUNCATE command such as |
For delete all records, We can use : |
For delete a particular record, use DELETE command with WHERE clause like: |
How can I set an alias for person table using few columns only? |
For this query we can use AS command as defined below: |
When we add a columns in the table we can done through ALTER command like : |
When we want to be do for like this then we can use ALTER command with DROP like this : |
When i wold like to drop the create table then we Use DROP TABLE command followed by table name. |
Using the Min function, we can know the average value of a numeric column. |
When we like to drop Database then we use DROP DATABASE command followed by database name : |
Using the Max function, we can know the average value of a numeric column. |
Using the Avg function, we can know the average value of a numeric column. |
Distinct Statement is basically use when in the table some of the columns may contain duplicate values. |
We are using Top clause(oracle) because if we like to know some limit of rows see in the output or some %age of the table we would like to show then we use this clause like : |
Now we want to select the employer with a last name that starts with \"A\" or \"n\" or \"k\" from the \"employer\" table. |
We want to select the employer with a first name that starts with any character, followed by \"Ka\" from the \"employer\" table. |
This wildcard we use when we want to show which name who start from some special char like : |
SQL Alias is the basically use for the make a easier to the query, I mean when you have a very long or complex table names or column names. Then we can use this function like : |
The INNER JOIN basically use for the return rows when there is at least one match in both tables. |
The FULL JOIN keyword is basically use for returning rows when there is a match in one of the tables. |
In some databases RIGHT JOIN is called RIGHT OUTER JOIN. The RIGHT JOIN keyword is basically use for the Returning to the all rows from the right table (table_name2), even if there are no matches in the left table (table_name1). |
In some databases LEFT JOIN is called LEFT OUTER JOIN. The LEFT JOIN keyword is basically a use for the returning the all rows from the left table (table_name1), even if there are no matches in the right table (table_name2). |
The ROUND() function is basically use for the round a numeric field to the number of decimals specified. |
The NOW() function is using for the returning the current system date and time. |
The FORMAT() function is basically used to format how a field is to be displayed. |
The LEN() function is basically use for the returning the value of length of the value in a text field. |
The MID() function is basically use for the extract the characters from the txt fields. |
The UNION operator is used to combine the result-set of two or more SELECT statements.Each SELECT statement within the UNION must have the same number of columns. |
The LCASE() function is basically use for the converts the field to Lowercase. |
The LAST() function is mainly use for the returning the Last value of the selected column. |
The UCASE() function is basically use for the convert the value of a field to uppercase. |
DATABASE statement is basically crate the CREATE DATABASE Command. |
The SQL SELECT INTO statement basically for the use in many fields and It can be used to create backup copies of tables. |
The CREATE INDEX statement is basically use for the create indexes in tables. Its mainly Indexes allow the database application to find data fast, without reading the whole table. |
The FIRST() function is used to the returning the first value of the selected column. |
Not NUll Constraints is basically means that we can\'t insert a new record, or also cant be update a record without adding a value to this field. The NOT NULL constraint enforces a column to NOT accept NULL values. The NOT NULL constraint enforces a field to always contain a value. |
To get the sum of a column .For example we want to know total pay to be paid : |
To group the results, use GROUP BY as in following: |