SQL WITH clause example [duplicate]

The SQL WITH clause was introduced by Oracle in the Oracle 9i release 2 database. The SQL WITH clause allows you to give a sub-query block a name (a process also called sub-query refactoring), which can be referenced in several places within the main SQL query. The name assigned to the sub-query is treated as … Read more

ORA-00904: invalid identifier

Your problem is those pernicious double quotes. Oracle SQL allows us to ignore the case of database object names provided we either create them with names all in upper case, or without using double quotes. If we use mixed case or lower case in the script and wrapped the identifiers in double quotes we are … Read more

What is a stored procedure?

Stored procedures are a batch of SQL statements that can be executed in a couple of ways. Most major DBMs support stored procedures; however, not all do. You will need to verify with your particular DBMS help documentation for specifics. As I am most familiar with SQL Server I will use that as my samples. … Read more

Case in Select Statement

I have an SQL statement that has a CASE from SELECT and I just can’t get it right. Can you guys show me an example of CASE where the cases are the conditions and the results are from the cases. For example: where the results show

Selecting COUNT(*) with DISTINCT

Count all the DISTINCT program names by program type and push number DISTINCT COUNT(*) will return a row for each unique count. What you want is COUNT(DISTINCT <expression>): evaluates expression for each row in a group and returns the number of unique, non-null values.

How to use mysqli_query() in PHP?

I have to admit, mysqli_query() manual entry doesn’t contain a clean example on how to fetch multiple rows. May be it’s because the routine is so routine, known to PHP folks for decades: In case you want to print the column titles, you have to select your data into a nested array first and then use keys … Read more

What is the difference between UNION and UNION ALL?

UNION removes duplicate records (where all columns in the results are the same), UNION ALL does not. There is a performance hit when using UNION instead of UNION ALL, since the database server must do additional work to remove the duplicate rows, but usually you do not want the duplicates (especially when developing reports). UNION Example: Result: UNION ALL example: Result:

What is an MDF file? [closed]

SQL Server databases use two files – an MDF file, known as the primary database file, which contains the schema and data, and a LDF file, which contains the logs. See wikipedia. A database may also use secondary database file, which normally uses a .ndf extension. As John S. indicates, these file extensions are purely convention … Read more