I have encountered a confusing problem with my table design for my media manager. Before insertion into a table called tbl_person I need to perform a procedure where I check if an actor aldready exists or not in the table tbl_castrole and if the actor does not exists in the latter table then I wan't insert the person in the tbl_person table.
The table tbl_person looks so far like this
And the table tbl_castrole looks like this
Before the insertion into the tbl_person table I wan't to do the checking in a method called
How would an sql query look like that checks if a person exists in two tables and has the same id in both of them? I am not a beginner when it comes to sql queries like this but I am very stuck here and are out of ideas. Also if the person exists should I insert this data in the tbl_person table with a unique identifier since there might be two or more persons with the same name in a movie? The latter is a side issue I haven't taken under consideration yet.
I hope I have been clear enough about what my problem is.
* Do you need the ORDER BY in the SELECT?
* I would put all the close() statements in a finally block so that they get closed whether or not the SQL statement produces an error. You'll have to surround them with a try/catch block because they may not have been opened. You can ignore the error.
All things are lawful, but not all things are profitable.
Thanks for the replies I have taken the advices and applied them to my code. I'm not quite satisfied becasue this query is really complicated for me at least. First off now there is three tables instead of the earlier two. The first is tbl_person, the second is tbl_crewrole and the third is tbl_castrole. I need a query that does the following: First check if input A is stored in tbl_person and if so, check if the ID for object A is stored in tbl_crewrole or tbl_castrole.
I hope there is someone here that can help me out. The latest thing that I have tried was this sql but it doesn't work