Skip to content

Automating Repeated Unions

I’m running a query like this: SELECT id FROM table WHERE table.type IN (1, 2, 3) LIMIT 15 This returns a random sampling. I might have 7 items from class_1 and 3 items from class_2. I would like to …

Primary key with two references

I would like that my relation table “In” has a Foreign key SSN which references to two tables, but the SSN is only in one of these two tables. When I do this: ALTER TABLE “In” ADD CONSTRAINT in_C1 …

Sum rows with no field to group by

I’m using SQL server 2012 and I’m trying to sum rows of a table. Problem is I don’t have a column to group by. Is this possible…? How would you raise the query? Original table: +—-+——+——…