I am not very good at making query’s. So could someone explain and help me with this query? I need to inner join 2 tables ‘Slaap’ And ‘Eten’. i need all ‘eten’ where ID = 5 and i need all ‘Slaap’ where ID = 5. I could only achieve this with a UNION but tha…
Tag: sql
Count nested records in SQL query
I have a problem that I need to select all owners who have 2 different companies where each company is on 2 different projects. For example : I tried to do like this : But it did not work. How to use a SQL query to solve this problem? For this case above, the query is expected to return: Answer
Cosmos db sql query for search in array
I have a document structure like below and I try to implement searching for user by fields author and partNames, so user can do query like SELECT * FROM c WHERE CONTAINS(c.author, ‘John’) and user will get in result the id=1 document because the name of author was John. The next step is to allow u…
SQL: join on foreign key between two tables and return only count of items; not actual items
I know there’s lots of questions similar to this out there. I’m writing my first SQL query; and I’ve been looking through SO but I can’t find out specifically what I’m doing wrong, because to me, they …
sql server – checking existence for each row in insert
I need to do an insert and check for each row if the field “partita_iva” is already in this table, if yes the field “flag” must be 1, if not then must be 0. I did this, but it set 1 for all the rows, …
How do you write a sql statement that creates a new column for a date value and then queries it in the WHERE clause
I have written a sql statement as so: SELECT * FROM ( SELECT DATEADD(dd, 60, PaymentDate) AS NewPaymentDate, * FROM MyTable ) x WHERE x.NewPaymentDate >=” & Date() & ” AND …
Aggregate quantity columns per distinct date in table sql
I want to sum quantity column from first date in table (2016-02-17 in this table) until per each distinct date in the table. Result relation should contains sum of quantities per each distinct date in …
Can’t delete records from the same table using NOT EXISTS MySQL syntax
I want to perform deletion in the same table. I’ve tried different ways, but I still can’t get it right. So, I got this error You can’t specify target table ‘tb’ for update in FROM clause. I tried aliasing the tables, but nothing done. I can’t figure out what is missing. I …
INSERT in CASE expression from subselect PostgreSQL
I am trying to create a query like this WITH insert1 as (), … subselect1 as (SELECT (CASE WHEN %s is NOT NULL THEN (INSERT INTO Duration (duration) VALUES (ROW (%s, %s)) …
How to get Date only from the datetime value?
I have an netezza SQL database field that looks like the examples below: Is there a way to select the first set of date to be date only like below: Answer Try to use built-in function DATE() in the following: