[SOLVED] Select Statement Failing lazarus / 16-Databases ---------------------------------------------------------------------- guest48180 · 2014-11-10 16:11 Using SQLite3, I have a databse with two tables: ATTENDEES & HISTORY. In HISTORY table, I have a Foreign Key that references ATTENDEE_ID from ATTENDEES table. I have two DBGrids on my form, one for each table. When a record is selected from ATTENDEES table, I'm trying to use that record's ATTENDEE_ID to access that person's history on HISTORY table. My select statement: Code: [Select]Query2.SQL.Text:= 'SELECT * FROM HISTORY WHERE FK_ATTENDEE_ID = ATTENDEES.ATTENDEE_ID'; Query2.ExecSQL; which produces the error: Code: [Select]no such column: ATTENDEES.ATTENDEE_ID So I tried: Code: [Select]Query2.SQL.Text:= 'SELECT * FROM HISTORY WHERE FK_ATTENDEE_ID = ' +Query1.FieldByName('ATTENDEE_ID').Value; Query2.ExecSQL; which gave me: Code: [Select]Invalid variant type cast I lit up Google last night trying to find examples for this, to no avail. Can someone set me on the right track? Much appreciated, Landslyde ---------------------------------------------------------------------- BigChimp · 2014-11-10 16:24 You're missing a JOIN (an INNER JOIN). You only specified one table in FROM so the db knows nothing about the other table. ---------------------------------------------------------------------- guest48180 · 2014-11-10 16:29 Quote from: BigChimp on November 10, 2014, 05:24:18 pmYou're missing a JOIN (an INNER JOIN). You only specified one table in FROM so the db knows nothing about the other table. Thank you, BigChimp  Landslyde