Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Saturday, October 8, 2011

SQL String Concatenation in Informix, MySQL and SQL Server

Like selecting the top N rows, syntax for string concatenation is DBMS-specific. The following are examples for Informix, MySQL and SQL Server.

Informix

select name || ' ' || surname
from customer;

MySQL

select concat(name, ' ', surname)
from customer;

Note: the MySQL concat() function can accept any number of arguments.

SQL Server

select name + ' ' + surname
from customer;

Monday, October 3, 2011

SQL Top n Rows in Informix, MySQL and SQL Server

Different dialects of SQL allow you to obtain the first n rows, resulting from a query, in different ways. The following are examples in Informix, SQL Server, and MySQL. Tip: to get the last n rows, simple switch the order by clause (from ascending to descending, or vice versa).

Informix

select first 5 *
from customer;

MySQL

select *
from customer
limit 5;

SQL Server

select top 5 *
from customer;