Monday, July 14, 2008

SQL where Group by order by having

Writing Complex SQL and ordering.. squence in which the key words must be arranged to prevent SQL Command not properly ended error.


SELECT <> FROM
WHERE
GROUP BY
HAVING
ORDER BY


EXAMPLE:

SELECT P_OID,BASE_CR_FAC_ID,COUNT(*) FROM
V_A_FAC_P_ITEM
WHERE PROPOSAL_ITEM_APPR_STATUS_CODE = 'discarded'
GROUP BY BASE_C_FAC_ID,P_OID
HAVING COUNT(*) >1
ORDER BY P_OID desc


Further Reading: http://www.java2s.com/Code/SQL/Select-Clause/UsingmathfunctioninHAVING.htm
- SQL ROCKS..!!!

No comments: