Recent

Author Topic: [SOLVED] Select Statement Failing  (Read 2608 times)

guest48180

  • Guest
[SOLVED] Select Statement Failing
« on: November 10, 2014, 05:11:55 pm »
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

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Select Statement Failing
« Reply #1 on: November 10, 2014, 05:24:18 pm »
You're missing a JOIN (an INNER JOIN). You only specified one table in FROM so the db knows nothing about the other table.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

guest48180

  • Guest
Re: Select Statement Failing
« Reply #2 on: November 10, 2014, 05:29:44 pm »
You'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

 

TinyPortal © 2005-2018