Postgresql – access/use joined subquery result in another joined subquery

I have a database with tables for equipment we service (table e, field e_id) contracts on the equipment (table c, fields c_id, e_id, c_start, c_end) maintenance we have performed in the past (table m,…

Two conditions based on subquery. How to shorten it?

I have working query basing on 2 subqueries. SELECT * FROM database1 where account_id in (SELECT account_id FROM (select account_id,transaction_id from … here i have my big sql query)) and …

SQL – Count rows based on matching columns and value range

Please see below query using T-SQL with SSMS. There are three tables: B, G and L. B has a column Bname G has 2 columns Gname, Gross L has 2 columns Bname, Gname Gross column is an INT ranging …

SQL – Find Record count for multiple tables at a time in snowflake

I want to see counts have Tables at 1 time, instead of Running each. For EX: select COUNT(*) from “Fact_MASTER “; select COUNT(*) from “Dim_MASTER “; select COUNT(*) from “…

Group and subquery issue

This is my sample data CREATE TABLE customer1 ( rating int(9), genre varchar(100), title varchar(100) ); INSERT INTO customer1 (rating, genre, title) VALUES (2, ‘A’, ‘abc’), (4, ‘A’, ‘…

How to speed up sql query execution?

The task is to execute the sql query: select * from x where user in (select user from x where id = ‘1’) The subquery contains about 1000 id so it takes a long time. Maybe this question was already …

Wrong syntax for OVER and PARTITION in MySQL syntax

SELECT Id, Price, CustomerId, ROW_NUMBER() OVER (PARTITION BY CustomerId) FROM Orders; I get the error “Syntax error: Unexpected ‘(‘ (opening parenthesis) Does MySQL not support this? I’m pretty …

How can I pull out the second highest product usage from a SQL Server table?

We have a product usage table for software. It has 4 fields, [product name], [usage month], [users] and [Country]. We must report the data by Country and Product Name for licensing purposes. Our rule …

How to select rows in parent table based on a value in child table

Consider the following tables, what would be an efficient query to return 1 row for each order that has at least 1 child row with a specific warehouse code? I am using SQL Server 2016. Table: Orders …

Joining two select statements together with outer join

My query on SQL Server: select s.learners_id, s.cv_student_id, s.first_name + ‘ ‘ + s.last_name student_name, p.program_name, dc.fulldate program_start_date, sd.discount_value, dt….