Concat all column values in sql

In SQL Server: SELECT col1 AS [text()] FROM foo FOR XML PATH (”) In MySQL: SELECT GROUP_CONCAT(col1 SEPARATOR ”) FROM foo In PostgreSQL: SELECT array_to_string ( ARRAY ( SELECT col1 FROM foo ), ” ) In Oracle: SELECT * FROM ( SELECT col1, ROW_NUMBER() OVER(ORDER BY 1) AS rn FROM foo MODEL DIMENSION BY (rn) … Read more

In SQL how do I get the maximum value for an integer?

In Mysql there is a cheap trick to do this: mysql> select ~0; +———————-+ | ~0 | +———————-+ | 18446744073709551615 | +———————-+ the tilde is the bitwise negation. The resulting value is a bigint. See: http://dev.mysql.com/doc/refman/5.1/en/bit-functions.html#operator_bitwise-invert For the other integer flavours, you can use the right bitshift operator >> like so: SELECT ~0 as max_bigint_unsigned … Read more

How to implement a Keyword Search in MySQL?

For a single keyword on VARCHAR fields you can use LIKE: SELECT id, category, location FROM table WHERE ( category LIKE ‘%keyword%’ OR location LIKE ‘%keyword%’ ) For a description you’re usually better adding a full text index and doing a Full-Text Search (MyISAM only): SELECT id, description FROM table WHERE MATCH (description) AGAINST(‘keyword1 keyword2’)