jb2003
jb2003

Reputation: 133

SQLite SQL error or missing database (no such table)

Hi everyone I am having some problems with my SQLite database in my java program. I am trying to retrieve data from a couple of tables but it says my table doesn't exist. I have checked using DB Browser and it's definitely there, so I'm not sure what I'm doing wrong. This is the error I receive:

[SQLITE_ERROR] SQL error or missing database (no such table: staff_clocked_in.clock_in_time)

SELECT * FROM staff, staff_clocked_in.clock_in_time WHERE staff.staff_id = staff_clocked_in.staff_id;

I'm sure my tables exist and there is data in both tables, here is a screenshot of my db browser.

enter image description here

If it helps, this is how I have setup my tables:

STAFF:

CREATE TABLE IF NOT EXISTS staff (staff_id INTEGER PRIMARY KEY NOT NULL, first_name TEXT NOT NULL, last_name TEXT NOT NULL, job_title TEXT NOT NULL);

STAFF_CLOCKED_IN:

CREATE TABLE IF NOT EXISTS staff_clocked_in (staff_id INTEGER PRIMARY KEY NOT NULL REFERENCES staff(staff_id), clock_in_time DATETIME NOT NULL);

Can anyone see anything wrong with my query? I'm not good with databases so hopefully it's just something simple.

Upvotes: 1

Views: 3709

Answers (1)

drescherjm
drescherjm

Reputation: 10837

The error message is correct staff_clocked_in.clock_in_time is not a table.

You should use staff_clocked_in instead which is your table.

So the fixed query should look like

SELECT * 
FROM staff, staff_clocked_in 
WHERE staff.staff_id = staff_clocked_in.staff_id;

Upvotes: 2

Related Questions