Which of the following statements are TRUE about an SQL query? P: An SQL query can contain a HAVING clause even if it does not have a GROUP BY clause Q: An SQL query can contain a HAVING clause only if it has a GROUP BY clause R: All attributes used in the GROUP BY clause must appear in the SELECT clause S: Not all attributes used in the GROUP BY clause need to appear in the SELECT clause

Which of the following statements are TRUE about an SQL query? P: An SQL query can contain a HAVING clause even if it does not have a GROUP BY clause Q: An SQL query can contain a HAVING clause only if it has a GROUP BY clause R: All attributes used in the GROUP BY clause must appear in the SELECT clause S: Not all attributes used in the GROUP BY clause need to appear in the SELECT clause Correct Answer Q and R

The correct answer is option 3

EXPLANATION:

GROUP BY clause:

  • The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country".
  • The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.

Syntax:

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)

Example:

SELECT COMPANY, COUNT(*)  
FROM PRODUCT_MAST   
GROUP BY COMPANY 

Therefore all attributes used in the GROUP BY clause must appear in the SELECT clause 

HAVING clause:

  • HAVING clause is used to specify a search condition for a group or an aggregate.
  • Having is used in a GROUP BY clause.
  • If you are not using GROUP BY clause then you can use HAVING function like a WHERE clause.

Syntax:

SELECT column1, column2   
FROM table_name  
WHERE conditions   
GROUP BY column1, column2   
HAVING conditions  
ORDER BY column1, column2;  
 
Example:
SELECT COMPANY, COUNT(*)  
FROM PRODUCT_MAST   
GROUP BY COMPANY  
HAVING COUNT(*)>2; 
Therefore an SQL query can contain a HAVING clause only if it has a GROUP BY clause.
Confusion Points
The answer is as per standard SQL

Related Questions

The conditions regarding selection from a list of suitable candidates to be called for interview after a written examination for appointment of management-level persons to a multi-national company providing accounting services and sales are mentioned below. Candidates: a) Must have a Bachelor's degree in Basic Science with 65% or more marks or BE with 55% or more marks. b) Must have passed the examination with 70% or more marks. c) Age must be between 25 to 30 years as of 1/4/18. d) Must have 3 years of experience in an Accounting Institution and must have a Diploma in Accounting with 60% or more marks. e) Must be currently getting CTC of Rs. 6 lakh or more per annum. If the candidate: 1) If he fulfills all the other conditions other than A above, he will be designated as Junior Accountant. 2) If he fulfills all the other conditions other than (d) and (e) above, he can be designated as Trainee-Accountant. If he fulfills all the above conditions including 5 years of experience, he can be designated as a Senior Accountant. He can be designated as Manager (Accounts) if he fulfills all the above criteria including educational qualifications of CA/ ICWA/ MBA (Finance). Study all the above information and answer the following question. Varun has passed the CA exam and has a bachelor's degree in basic science and a diploma in accountancy, having scored 75% or more in the written examination during his entire career and also in the written examination. His age is 27 years and with 4 years of experience in Accountancy, he has a CTC salary of 18 lakhs per annum. To which of the following positions can he be referred? Select from the given options.
A passage is given with five questions following it. Read the passage carefully and select the best answer to each question out of the given fouralternatives. Just as space permeates everything in the universe, love permeates every part, every aspect of creation. If there is one answer to the question, “How and why doesthis world exist?” the answer, in one word, is Love. Rather, the answer is Pure Love, since the word love has lost its meaning. Your very existence is an expression of pure unconditional love of the Source (you may call it Consciousness, Creator, God, Divine Self). This is the truth of your being.True love transcends both love and hatred. It is unconditional, unquestioning, boundless, unchanging love. It is overflowing love of the Source for the Source throughall of creation. True love is way beyond the personalized love that two or more individuals assert on one another. Personalized love, though apparently selfless, is rooted in desiresand conditional satisfaction. We have been brought up in a society that judges love based on conditions. We have been made to believe that we can receive love only when we fit into peoplesexpectations. If we are not good enough, we will be deprived of love. These beliefs have influenced the collective psyche of families, groups, communities, and societies since generations to such an extent that love has been reduced tofear of denial. We need to shift from the paradigm of false conditional love to the essence of pure unconditional love . The experience of true love comes with surrender of the false I, in letting go of the feeling of separateness. Without this sacrifice, it is not possible to attain divinelove. When this separate I is discarded, you embrace everything in oneness and catch a glimpse of pure love. True love can be experienced only through giving, not by demanding. People who exist in your life are not here to love you. They are here to remind you that you arethe Source of Love. By knowing that you are the Source of love, you can love yourself, instead of waiting to receive love from the world. Ask yourself, “Why do I need an agent to love myself?” Waiting for the world to love you, is like hiring an agent to love yourself! It is time for you to honor yourself as the Source of love. You have undertaken this human journey to realize and express the boundless love that you truly are. According to the passage, which of the following statement is not TRUE?
A passage is given with five questions following it. Read the passage carefully and select the best answer to each question out of the given fouralternatives. Just as space permeates everything in the universe, love permeates every part, every aspect of creation. If there is one answer to the question, “How and why doesthis world exist?” the answer, in one word, is Love. Rather, the answer is Pure Love, since the word love has lost its meaning. Your very existence is an expression of pure unconditional love of the Source (you may call it Consciousness, Creator, God, Divine Self). This is the truth of your being.True love transcends both love and hatred. It is unconditional, unquestioning, boundless, unchanging love. It is overflowing love of the Source for the Source throughall of creation. True love is way beyond the personalized love that two or more individuals assert on one another. Personalized love, though apparently selfless, is rooted in desiresand conditional satisfaction. We have been brought up in a society that judges love based on conditions. We have been made to believe that we can receive love only when we fit into peoplesexpectations. If we are not good enough, we will be deprived of love. These beliefs have influenced the collective psyche of families, groups, communities, and societies since generations to such an extent that love has been reduced tofear of denial. We need to shift from the paradigm of false conditional love to the essence of pure unconditional love . The experience of true love comes with surrender of the false I, in letting go of the feeling of separateness. Without this sacrifice, it is not possible to attain divinelove. When this separate I is discarded, you embrace everything in oneness and catch a glimpse of pure love. True love can be experienced only through giving, not by demanding. People who exist in your life are not here to love you. They are here to remind you that you arethe Source of Love. By knowing that you are the Source of love, you can love yourself, instead of waiting to receive love from the world. Ask yourself, “Why do I need an agent to love myself?” Waiting for the world to love you, is like hiring an agent to love yourself! It is time for you to honor yourself as the Source of love. You have undertaken this human journey to realize and express the boundless love that you truly are. Which of the following statement(s) is/are TRUE about pure love?
A passage is given with five questions following it. Read the passage carefully and select the best answer to each question out of the given fouralternatives. Just as space permeates everything in the universe, love permeates every part, every aspect of creation. If there is one answer to the question, “How and why doesthis world exist?” the answer, in one word, is Love. Rather, the answer is Pure Love, since the word love has lost its meaning. Your very existence is an expression of pure unconditional love of the Source (you may call it Consciousness, Creator, God, Divine Self). This is the truth of your being.True love transcends both love and hatred. It is unconditional, unquestioning, boundless, unchanging love. It is overflowing love of the Source for the Source throughall of creation. True love is way beyond the personalized love that two or more individuals assert on one another. Personalized love, though apparently selfless, is rooted in desiresand conditional satisfaction. We have been brought up in a society that judges love based on conditions. We have been made to believe that we can receive love only when we fit into peoplesexpectations. If we are not good enough, we will be deprived of love. These beliefs have influenced the collective psyche of families, groups, communities, and societies since generations to such an extent that love has been reduced tofear of denial. We need to shift from the paradigm of false conditional love to the essence of pure unconditional love . The experience of true love comes with surrender of the false I, in letting go of the feeling of separateness. Without this sacrifice, it is not possible to attain divinelove. When this separate I is discarded, you embrace everything in oneness and catch a glimpse of pure love. True love can be experienced only through giving, not by demanding. People who exist in your life are not here to love you. They are here to remind you that you arethe Source of Love. By knowing that you are the Source of love, you can love yourself, instead of waiting to receive love from the world. Ask yourself, “Why do I need an agent to love myself?” Waiting for the world to love you, is like hiring an agent to love yourself! It is time for you to honor yourself as the Source of love. You have undertaken this human journey to realize and express the boundless love that you truly are. What does source refers to in the last line of the second para of the passage?
A passage is given with five questions following it. Read the passage carefully and select the best answer to each question out of the given fouralternatives. Just as space permeates everything in the universe, love permeates every part, every aspect of creation. If there is one answer to the question, “How and why doesthis world exist?” the answer, in one word, is Love. Rather, the answer is Pure Love, since the word love has lost its meaning. Your very existence is an expression of pure unconditional love of the Source (you may call it Consciousness, Creator, God, Divine Self). This is the truth of your being.True love transcends both love and hatred. It is unconditional, unquestioning, boundless, unchanging love. It is overflowing love of the Source for the Source throughall of creation. True love is way beyond the personalized love that two or more individuals assert on one another. Personalized love, though apparently selfless, is rooted in desiresand conditional satisfaction. We have been brought up in a society that judges love based on conditions. We have been made to believe that we can receive love only when we fit into peoplesexpectations. If we are not good enough, we will be deprived of love. These beliefs have influenced the collective psyche of families, groups, communities, and societies since generations to such an extent that love has been reduced tofear of denial. We need to shift from the paradigm of false conditional love to the essence of pure unconditional love . The experience of true love comes with surrender of the false I, in letting go of the feeling of separateness. Without this sacrifice, it is not possible to attain divinelove. When this separate I is discarded, you embrace everything in oneness and catch a glimpse of pure love. True love can be experienced only through giving, not by demanding. People who exist in your life are not here to love you. They are here to remind you that you arethe Source of Love. By knowing that you are the Source of love, you can love yourself, instead of waiting to receive love from the world. Ask yourself, “Why do I need an agent to love myself?” Waiting for the world to love you, is like hiring an agent to love yourself! It is time for you to honor yourself as the Source of love. You have undertaken this human journey to realize and express the boundless love that you truly are. According to the passage, whom to honour as the source of love?