subquery

ms access, need to get all rows with a distinct column

一曲冷凌霜 提交于 2021-02-19 08:13:05
问题 I have a table called "parts" which stores information on electrical connectors including contacts, backshells etc. all parts that are part of an assembly have a value in a column called "assemblyID". There is also a column called "partDefID", in this column connectors will have a value of 2, contacts will be 3. I need to get rows for all connectors that have a unique assemblyID. It's easy to get rows that represent connectors just by selecting rows with a partDefID of 2 but this will return

Select max value in subquery

我只是一个虾纸丫 提交于 2021-02-19 05:47:03
问题 I have these two tables: Student: | name | email | |---------------------|-------------------------| | Arturo Vidal | arturo.vidal@usm.cl | | Bastian Quezada | bastian@usm.cl | | Javier Jeria | javier@usm.cl | | Sebastian Piñera | sebastian@presidente.cl | | Sebastian Gallardo | sebastian@usm.cl | Class: | classId | email | signUpDate | |---------|-------------------------|-------------| | 1 | sebastian@usm.cl | 2018-01-01 | | 1 | javier@usm.cl | 2019-10-01 | | 1 | bastian@usm.cl | 2018-07-01

LEFT OUTER JOIN Error creating a subquery on bigquery

ぃ、小莉子 提交于 2021-02-18 19:29:32
问题 I'm trying to eval MAL, WAL and DAU from a event table on my bq... I create a query find DAU and with him find WAU and MAU, but it does not work, i received this error: LEFT OUTER JOIN cannot be used without a condition that is an equality of fields from both sides of the join. It's my query WITH dau AS ( SELECT date, COUNT(DISTINCT(events.device_id)) as DAU_explorer FROM `workspace.event_table` as events GROUP BY 1 ) SELECT date, dau, (SELECT COUNT(DISTINCT(device_id)) FROM `workspace.event

Selecting rows from a table with specific values per id

匆匆过客 提交于 2021-02-11 14:16:54
问题 I have the below table Table 1 Id WFID data1 data2 1 12 'd' 'e' 1 13 '3' '4f' 1 15 'e' 'dd' 2 12 'f' 'ee' 3 17 'd' 'f' 2 17 'd' 'f' 4 12 'd' 'f' 5 20 'd' 'f' From this table I just want to select the rows which has 12 and 17 only exclusively. Like from the table I just want to retrieve the distinct id's 2,3 and 4. 1 is excluded because it has 12 but also has 13 and 15. 5 is excluded because it has 20. 2 in included because it has just 12 and 17. 3 is included because it has just 17 4 is

HQL unexpected token “(” subquery select

五迷三道 提交于 2021-02-11 13:50:21
问题 I have this query. Translate it from my sql query to hql. I have this error "unexpected token: ( near line 2, column" String query = "SELECT MAX(number)\n" + " FROM (SELECT number FROM EmployeeTripCard \n" + " WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" + " UNION ALL\n" + " SELECT trip_card_number FROM PostgraduateTripCard\n" + " WHERE EXTRACT(YEAR FROM issueDate) = '2015'\n" + " UNION ALL\n" + " SELECT trip_card_number FROM StudentTripCard \n" + " WHERE EXTRACT(YEAR FROM issueDate) =

MYSQL nested query running very slow?

淺唱寂寞╮ 提交于 2021-02-09 19:04:21
问题 The following query is constantly timing out, is there a less overhead way to achieve the same function ? UPDATE Invoices SET ispaid = 0 WHERE Invoice_number IN (SELECT invoice_number FROM payment_allocation WHERE transactionID=305) What I'm doing is unallocating invoices from a transaction, there can be up to 30+ records returned but it stops the database dead everytime I try to run it 回答1: USE JOIN instead of subquery it will improve the performance. Create index on Invoice_number column in

MYSQL nested query running very slow?

折月煮酒 提交于 2021-02-09 19:03:38
问题 The following query is constantly timing out, is there a less overhead way to achieve the same function ? UPDATE Invoices SET ispaid = 0 WHERE Invoice_number IN (SELECT invoice_number FROM payment_allocation WHERE transactionID=305) What I'm doing is unallocating invoices from a transaction, there can be up to 30+ records returned but it stops the database dead everytime I try to run it 回答1: USE JOIN instead of subquery it will improve the performance. Create index on Invoice_number column in

MYSQL nested query running very slow?

ぃ、小莉子 提交于 2021-02-09 18:58:09
问题 The following query is constantly timing out, is there a less overhead way to achieve the same function ? UPDATE Invoices SET ispaid = 0 WHERE Invoice_number IN (SELECT invoice_number FROM payment_allocation WHERE transactionID=305) What I'm doing is unallocating invoices from a transaction, there can be up to 30+ records returned but it stops the database dead everytime I try to run it 回答1: USE JOIN instead of subquery it will improve the performance. Create index on Invoice_number column in

Get variable MIN Date based on marker in row

和自甴很熟 提交于 2021-02-08 08:20:41
问题 I'm using MySQL with phpMyAdmin , below is my data table: +--------+---------+-----------------+ | userID | context | time | +--------+---------+-----------------+ | 111 | | 7/1/2021 | | 111 | | 7/16/2019 | | 111 | Reset | 7/15/2019 | | 222 | | 7/9/2020 | | 222 | Reset | 7/8/2020 | | 333 | Reset | 5/11/2020 | | 333 | | 5/10/2020 | | 444 | | 9/8/2020 | +--------+---------+-----------------+ I'm looking for a SELECT query that gives me the MIN time greater or equal to the date where a Reset is

mySQL correlated Subquery

徘徊边缘 提交于 2021-02-07 19:56:33
问题 trying to write a mysql query and having a lot of difficult with this one. I have two tables( Item: info about items, and itemReview: reviews for the items ) What I would like to do is select all the items that belong to a particular location (which is what my outer query does) and then for each item in the outer query, get the average of all the rating fields in the itemReview table Here is my attempt: SELECT Item.idDish, Item.dateAdded, Item.dateModified, Item.fidLocation, Item.category,