Given table: +—+——-+——+—+ |id | attr | fker |did| +—+——-+——+—+ |1 | attr1 | 5 | 1| |2 | attr1 | 17 | 1| |3 | attr1 | 3 | 2| |4 | attr2 | 31 | 2| |5 | attr2 |…
Tag: mysql
Select only products that are active via query from two tables
I have a query that provides me with a list of productId:s that I then match with a products table.. But how would I adjust the query to give me only productId:s that are active (active=1)? Answer You can use join:
Populating a recordset between two positions in a table using MYSQL
I’m trying to write a query that will only return a recordset between 2 positions in a table For example, using Excel to demonstrate, populate a recordset between positions 3 and 7 I thought about using BETWEEN with the ID field, but there may be times that a record has been deleted and the ID field aut…
Subquery – define select list. The subquery returns the same value for each result line
do you know what I have done wrong? My subquery is returining the same value for all lines. Thanks a lot in advance for your any advice! 🙂 Answer I think you just want conditional aggregation:
SQL – How to select date from the past 5 years to include 1st of Jan of the oldest year
I am trying to select data entered for the past 5 years (to start from the 1st of Jan of the first or oldest year). I’ve constructed the query below but it does not begin from the 1st of January of the oldest year. Any help would be appreciated. Answer You seem to be using MySQL. The simplest method is
SQL Get users with max occurrences in table
Given the following table transactions, which records the IDs of sellers and buyers who had a transaction, I would like to determine the user who was involved in the highest number of transactions and …
Get sum of column with distinct id in SQL
I am trying to get sum of the amount on distinct ext_id. Id Ext_id amount 1 234 5 2 234 5 3 235 10 4 236 8 5 236 8 Select SUM(amount) from Table1 — this will get me sum of all  => 36 I want just sum of distinct Ext_id which should be 23. Can someone help me with this?
JPA query is throwing a ‘not found’ error for column that isn’t in query
I’m trying to call for only specific columns in my DB but the query is throwing an error saying that the next column is not found (even though it’s not in the query) Is there a problem in the join that’s doin this? I’m a bit perplexed as to this problem. JPA Query from ConnectionReques…
MySQL – Join tables to a custom list/array of values
I would like to know if it’s possible to join tables into a custom set of values in MySQL. For example, I have a set of dates (outside the database). I would like to get the matched joins in a single query so that I can easily loop through the result. Like: Data outside database Date 2021-04-08 2021-04-…
SQL get total sellers of product category
I have like this database tables: Table categories Table products Table product_varieties I have query to get price min, max and avg in each category: Now I need get total users (sellers) of each category by editing my current query. I tried like this: But my query not work and return error with message: How …