#!/usr/bin/perl -T use strict; use warnings; use DBI; my $db = DBI->connect('dbi:SQLite:dbname=blubb.db', '', '', { RaiseError => 1 }); my $stmt = $db->prepare(<<'EOD'); SELECT (CASE WHEN t.lang ISNULL THEN (SELECT name FROM translations WHERE id = i.id) ELSE t.name END) AS name FROM items AS i LEFT OUTER JOIN translations AS t ON i.id = t.id AND t.lang = ? WHERE i.id = ? AND i.level = ?; EOD sub x { printf "lang = %s, id = %d, level = %d ==> ", @_; $stmt->execute(@_); print $stmt->fetchrow_array(); print "\n"; } x('is', 2, 1); x('de', 2, 1); $stmt->finish(); $db->disconnect();