Unknown column 'r' in 'where clause' SELECT typ,foreign_id FROM new_system WHERE system_id = r AND typ = 'kod'