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