back up codes

always have a backup of your code

Archive for the tag “sql”

sql WHERE clause with AND & OR

The SQL WHERE clause is used to display records that fulfills a specified condition.

The following is the syntax of the WHERE clause:


SELECT myColumn1, myColumn2, myColumn3
FROM myTable WHERE columnName operator value

The operator can either be , =, IS, ISNOT.

The value can be a string, numerical, NULL.

AND & OR Operator

The AND & OR operators are used to display records based on more than one condition.

The AND operator displays a record if both the first condition and the second condition is true.
The OR operator displays a record if either the first condition or the second condition is true.

SQL AND syntax


SELECT * FROM myTable
WHERE columnName operator value AND columnName operator value

sql ORDER BY keyword

The SQL ORDER BY keyword is used to display the result of a specified column either in ascending or descending order.

By default resulting record is in ascending order, and if sorting of records should be in descending order, the DESC keyword is used.

The SQL syntax for the ORDER BY keyword.


SELECT * FROM myTable ORDER BY myColumn1 ASC|DESC

select the first row in sql select statement

The following sql statement will retrieve the first row from a select statement:


SELECT TOP 1 * FROM MY_TABLE ORDER BY THE_PK DESC

select the second row in a select statement

The following code will select the second row in an sql select statement.


SELECT TOP 1 * FROM (SELECT TOP 2 * FROM MY_TBL ORDER BY MY_DATE ASC ) AS VALUE ORDER BY MY_DATE ASC

Post Navigation

Follow

Get every new post delivered to your Inbox.