Question
What is CTE (Common Table Expression)?

Answers

When a complex SQL statement has number of joins then it can be made easier by using Common Table Expression.
Consider the following SQL statement.
SELECT * FROM (
SELECT emp.EmpName,dept.Department,emp.Gender FROM Employee emp
left join Department dept on emp.DeptID = dept.DeptID) E
WHERE E.Gender = ‘Male’
ORDER BY T.EmpName

The syntax of CTE is as follow
- The CTE Name (followed by WITH keyword)
- The Column List (Optional)
- The Query (Appears within parentheses after the AS keyword)

If we write the above messy query using CTE it would be like:
With E(EmpName, Department, Gender)
AS
(
SELECT emp.EmpName,dept.Department,emp.Gender FROM Employee emp
left join Department dept on emp.DeptID = dept.DeptID
)
SELECT * FROM E
WHERE E.Gender = ‘Male’
ORDER BY E.EmpName
This way the query can be made more readable and easy to understand.   Your Comment




More Software Questions..
What is the inputsplit in map reduce software?

What is software configuration management?

What Is Java Api For Xml-based Rpc (jax-rpc)?

How can you implement fine-grained auditing?

What is IBM’s simple explanation for Big Data’s four critical features?

What is static synchronized method in JDBC API? Give an example?

What does the NULLIF function do?

What happens if a start method is not invoked and the run method is directly invoked?

Should we override finalize method

what is the difference between mysql_fetch_array and mysql_fetch_object?

How will XML affect my document links?

Why to use Style Sheets?

What are Filters in MVC?

Can you explain Application layer in OSI model?

How to define new testplan attributes?

What are the minimum system requirements to run Photoshop? Is it possible to run Photoshop over linux?

Which oracle package is used to manage the oracle lock management services?

What is Latch Up? Explain Latch Up with cross section of a CMOS Inverter. How do you avoid Latch Up?

What is marker interface?

What types of partitioning are there for BW?



Search
Can you Answer!!
  • Q What are Accessors, mutators, @property?
  • Q What are KRAs/outputs of position: BI publisher?  
  • Q Researchers in Mumbai have found that certain types of gallstones can be dissolved by injecting them with a gasoline additive in the form of ether the ether is injected through a tube directly into a tube directly into the gallbladder the one day treatment works only on cholesterol-based stones not those composed largely on calcium However as the cholesterol stones are by far the most common type for millions of gallstones sufferers the treatment should offer a welcome alternative to surgery the commonest option in most hospitals. injecting ether into the gall bladder dissolves most gallstones
  • Q What are the characteristics of a creative child?
  • Q What is strong name and what is the purpose of strong name
  • Q What web developer should know?
  • Q Cyclonite is other name of an explosive.What is that ?
  • Q Is the nervous system in platyhelminthes more or less sophisticated than in cnidarians? What are the main neural structures found in flatworms? How is this neural organization important for the diversity of biological niches explored by species of the phylum?
  • Q How can you speed up data transfer in Snowball?
  • Q What is the role of Iodine in killing germs?
  • Q Write Notes on Adjuvants