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:
Tag: sql
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 use Lead() and Lag() to get the first non null value
I have the following query and returns this table: now, what I’m trying to do is to calculate the lead of the first non null value on the field. for example, for event_id = 138466815 the columnCount is 85. I want the “lead1” field to show 82.53, which is the next non null value below. and th…
Access SQL query – select date range from specific day of the month
I have been scratching my head over this for a while, but i would like to make a query that selects values from the 24th of the current / last month to the 24th of the next/current month depending on the month we are in – this is basically from one payroll to the next. any suggestions on the SQL
A homework question: is there a way to compare contents in different tables at the same time?
The part of the schema is as follows: Customer (cid, name, city) (primary key: cid) Purchase (cid, club, title, year, when, qnty) (primary key: cid, club, title, year, when) I want to list distinct pairs of customers who have made a purchase of a book (title) in common. For each pair of such customers, show f…
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…
Find the row violating the constraint to be added
I’m trying to add a check constraint to a table like ALTER TABLE foo ADD CONSTRAINT bar CHECK (…); and I get the error: ERROR: check constraint “bar” is violated by some row ********** Error ****…