Palindromes Puzzle

Itzik introduces a querying puzzle - producing palindromes with T-SQL. Up for the challenge?

Itzik Ben-Gan

January 20, 2007

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Given the following table of words:

create table words(word varchar(50) not null primary key);

insert into words values('even');
insert into words values('never');
insert into words values('odd');
insert into words values('or');
insert into words values('madam');
insert into words values('adam');

Write a query that produces all possible palindromes (sentences that look the
same when spelled backwards) made of unique words.
The desired output for the given sample data is:

palindrome------------------madamnever evennever or evennever odd or evenmadam adam

Cheers,
--
BG

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like