Skip to content

Tag: sql

Foreign Key on MySQL

I am new to SQL and I started building my own project. I am having issues creating a foreign key on my second table. . Please let me know what I am missing here. Answer The second CREATE TABLE statement should be:

How to take union and write into the same table?

I have a table A with columns (x, y, z) and I have another table B with columns (x, y, z), basically the same schema. I want to add those rows from B into A, which do not already exist in A, basically after the operation the union of A and B exist in table A. How do I do

JDBC, Prepared Statement getInt() returns 0

In my DB every question has a valid questionID (primary Key) and categoryID (foreign Key to category table). The problem is: in the Result Set for every question both IDs are 0 instead of what’s written in the DB. All other arguments are filled out correctly. Edit 1 Here is the original code (in the pos…

Update value if exist or insert in SQL with C# linq

I have this code which is working fine and I update a value if exists or insert if not With this code I manage to do the work with only one query to the SQL, but I was wondering if there is an easier or more elegant way to do it. For example if I could use linq and lambda

SELECT from table where id is not represented with another user_id

I’m trying to select rows, where the id_imported_urls is only present on the current user, but i cant figure out how to make the SQL call properly. Answer With NOT EXISTS: This will return a row only if id_imported_urls = 23965 does not exist for any user_id <> 4 . This query: returns all the id_i…

How to check if two columns are consistent in a table. sql

I’m struggling to ask the question so I will just put an example table. Basically, if I have two columns with headings person and insured car, how can I check if the same person consistently insures the same brand of car. So basically in this table I want to filter out person 0 because he insures both T…