Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How would you delete a value from a column in a table when that column value refers to two different tables.

Need a SQL Query here using Joins

What I have tried:

Tried Googling Not getting anything specific
Posted
Updated 30-Nov-18 10:17am
Comments
Sinisa Hajnal 30-Nov-18 2:02am    
What do you mean it "refers to two different tables"? If you store value from two tables in the same column, rethink your design. Also, you didn't really try anything, write an SQL query, see what works and what not and ask help with that.
vaibhav1800 30-Nov-18 8:42am    
I meant if that column is referred in multiple tables, so that means its a foreign key there and there would be , lets say 4 primary key equivalent to it in 4 different tables. So Need a SQL Query in MYSQL TO delete a value from a column in the table where it is foregin key
OriginalGriff 30-Nov-18 2:12am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
Xynosural.net 30-Nov-18 7:16am    
are we talking about mysql? mssql ? postgre ? access ?
vaibhav1800 30-Nov-18 8:42am    
MYSQL

1 solution

has been a while for me but.. try something like this:

DELETE FROM table1 t1, table2 t2
WHERE t1.id = 1 AND t2.parent_id = t1.id

Please let know if this method works, i am not 100% sure
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900