hi, I have these two tables:

personal_details (staff_ID integer PRIMARY KEY, title varchar(10), fn varchar(250), ln varchar(250), mn varchar(250), dob varchar(50), hometown varchar(250), securityno varchar(50), phone varchar(15), phone2 varchar(15), phone3 varchar(15), email varchar(50), address varchar(300), confirmation varchar(50), retirement varchar(50));

and

training(
	training_ID integer primary key NOT NULL,
	staff_ID varchar(100),
	training_level varchar (60),
	school_name varchar(100),
	training_date varchar(100));

When I make the following query, I get the following error:

SQLite error ambiguous column name: staff_ID

Im sure there is something wrong my tables schemas. Please help me correct it. By the way Im using vb.net.Thanks

Recommended Answers

All 3 Replies

Where is the query? Anyways following query may help you.
Always use table alias before column name when you are querying more than one table.

select p.staff_ID , p.title , p.fn , p.ln ,
t.training_id, t.training_level, t.school_name, t.training_date
from personal_details p
inner join training t on t.staff_id=p.staff_id

Thanks for answering and sorry for the query I failed to post. This is the query the Im using:

SELECT personal_details.fn, training.training_level FROM personal_details INNER JOIN training ON personal_details.staff_ID = '" + detailsFrm.Label13.Text + "'

The query above and yours are giving me the following error message:

One or more rows contain values violating non-null, unique, or foreign-key constraints.

I think the problem should be from my table schemas. Please help me correct. Thanks

I am not sure about the error. It seems there there is some problem with some of the row. are you able to query two tables separtely without joining?. You empty both tables and then again insert fresh rows.

And now about your query. I have corrected your query as given below

SELECT personal_details.fn, training.training_level 
FROM personal_details INNER JOIN training 
ON personal_details.staff_ID = training.staff_id 
where personal_details.staff_id='" + detailsFrm.Label13.Text + "'

You must complete the join condition, the filter record with where clause.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.