Questions tagged [query]

Writing queries to request or change information stored in a database or other information management system. Questions should include table and index definitions, sample data, expected output, and a tag for the specific system (e.g. MySQL, PostgreSQL, Oracle, SQL Server, MongoDB).

Filter by
Sorted by
Tagged with
-2 votes
0 answers
37 views

query to get start time and end time from same column based on boolean value order by primary key with average and max fields [closed]

The first part of the question is the same as in this question (query to get start time and end time from same column based on boolean value order by primary key), but there are two more fields in the ...
  • 1
0 votes
0 answers
16 views

I want to simplify my sum query using loop function

I have a query to summerize my data based on month between year 2021 - next years (depend on the real date) i used simple query like this to summerize the amount monthly SUM(IF(pt.description like '%O-...
0 votes
0 answers
22 views

write a sql statement to count the data that meet a certain condition in every minute in TDengine

I have a sql statement in time-series database TDengine. select count(*) as count from iot.things_model_meters where model_identifier = 'online' interval(1m) sliding(1m); Like this statement ...
0 votes
2 answers
94 views

Get movies that played in all cinemas

I stumbled upon a problem of selecting movies that have been played in every cinema (theaters). All I'm looking for right now is getting the IDs of movies that match this condition, then I will join ...
  • 103
0 votes
1 answer
15 views

mysqli_fetch_array exceeds memory

I a running a relatively simple query: SELECT gb2_designs.indx, gb2_designs.response_required, gb2_designs.user_design_name, ...
-2 votes
0 answers
27 views

Stuck with Database query

If I am running query - select date , sum(orders) as "Total orders" from tbl where date >=1 and date <=4 group by date How can I get the expected output as shown in the picture. (I ...
0 votes
1 answer
24 views

In MS Access 2019, how do I find numbers in a lottery table that appear often together?

I have a table with 256 lottery drawings, pick 5, along with the drawing date. I want to know how many times my favorite numbers (4,7,47) or any numbers, came out at the same drawing. I am thinking ...
0 votes
1 answer
32 views

SQL query to get the order of procedures based on their dependent procedures

i have this query to get all sp's and depending(nested) sp's on those sp's. I need to create all these procedures on another database . Any idea how to get them in the correct order. select distinct ...
0 votes
1 answer
36 views

SQL query to script all objects from a database in order

i have a script to get all objects (functions ,views ,triggers and procedures from a database . I need to create this in another database . The problem is some procedures may have another procedures ...
0 votes
1 answer
33 views

Sql server Intellisense is not working

My sql server management studio intellisense is not working, below is my SSMS version and screen shot that I have tried, my SQL server is not installed locally but I am accessing the sql server ...
1 vote
1 answer
30 views

How do I model a Cassandra table that stores friends of a user?

Recently I started to learn Cassandra. I needed to design the database for my web application. So, I prepared conceptual data model as well as application workflow, and currently I’m stuck on ...
0 votes
1 answer
53 views

Query with stored procedure

I have a query that grabs data from a .csv and inserts into a table I created, now I need to take a single column from my destination table and use it to gather data from another database from another ...
-2 votes
1 answer
25 views

MS SQL Server : How to get query history along with SQL id and the user who triggered the query

I know this is a duplicate one. But i did not find a solution for my requirement in this forum. Is there a way to identify the list of completed queries that were triggered along with its SQL ID and ...
  • 1
0 votes
0 answers
13 views

query get data from one table and join other data from 2 tables where the same ID

This query get data from table products and JOIN data from product_details with rule check the same product ID. $query = "SELECT p.id, p.slug, p.sku, ...
0 votes
1 answer
40 views

Retrieve all linked categories

I have Categories stored in a single table. Where there is no limit on number of childerns. I want to fetch all the linked categories for the provided category id: The reason for getting the hierarchy ...
0 votes
1 answer
42 views

Data normalization on insertion

Please excuse the noob question but SQL is not where my strength lies. Let's say that I have a table where I am storing users' data. Typically there are columns of type TEXT such as name, email... e.g....
  • 103
4 votes
2 answers
259 views

Case-Sensitive Collation on a select query in SQL Server

Our SQL Server's collation is set to SQL_Latin1_General_CP1_CI_AS I have a requirement where we have the same values with different cases but SQL Server treats them the same since our collation is set ...
0 votes
0 answers
19 views

Customer Billing System (Charges, Discounts, Payments, Refunds, Adjustments)

General Overview I am trying to design a relational schema in PostgreSQL to handle billing for course enrollments and other services/fees. The system needs to be able to handle the following: Charges ...
0 votes
2 answers
47 views

Understanding how Nested Loop expected rows works

Postgres 13.5 I have a query where the plan it comes up with creates (via nested loops) huge numbers of rows, spends hours processing them, and then promptly discards them (Rows Removed by Filter: big ...
  • 103
1 vote
1 answer
27 views

mariaDB query/update very slow (timout) first time

Maybe just forget everything below... After investigating, adding indexes we do get other results, and other queries becoming slow... We really helps is this: Another VM (all the same image) Open ...
  • 9
0 votes
2 answers
45 views

Converting string with DIN 1421 pattern to human-readable

In the Oracle DB there is a table that stores "DIN"s attribute (VARCHAR2(1200 BYTE)), see a table/image below. Each string follows the DIN 1421 pattern. +------------------+ | DIN ...
  • 177
0 votes
0 answers
22 views

Append Data from 1 Table to Another with Image Column Across Linked Server

MSSQL - I am trying to append data from Table 1 that doesn't exist in Table 2. The tables have the same columns. One of the columns is image format and is not 'comparable'. Table 2 is across a ...
0 votes
1 answer
47 views

MariaDB MATCH AGAINST using + in BOOLEAN MODE

I am having a problem with searching a MariaDB database. Search keywords come from user-input, processed with PHP, SQL query made and results returned. In it's simplest form :- CREATE TABLE db ( ...
1 vote
0 answers
27 views

How to populate a column of a table from multiple tables?

I imported into PostgreSQL a layer which I created an identifier allowing to make a join in order to recover geometries. These geometries are distributed in several layers and some geometries are ...
  • 113
-1 votes
1 answer
65 views

SQL SERVER SELECT COLUMN JSON ARRAY

I have a json in column of table SQL Server: { "_id":{ "$oid":"61ccdc232d1e0a844149faba" }, "report":{ "description":"...
  • 3
-1 votes
2 answers
65 views

SQL - Join column with condition if it is <> Blank

I want to join two tables together using ColumnA and ColumnB. However, ColumnB is sometimes a blank string. If ColumnB is blank, I just want to to join using ColumnA. But if ColumnB is not blank, I ...
0 votes
0 answers
11 views

To_number() function with rpad() function , how it works?

I saw this piece of code and I have no idea how it works . I was wondering if you could help me figure it out : column Col_one data type is number and you can see the code below: select to_number([...
  • 1,376
0 votes
1 answer
24 views

How to get rid of all whitespace in a mysql query?

SELECT libary.MediaId, library.Title, library.`date-downloaded`, library.Author, library.`language`, library.asseturl, library.`recycle-bin`, library.`key-asset`, SUBSTRING_INDEX(SUBSTRING_INDEX(`...
  • 535
6 votes
2 answers
150 views

Querying the sys.dm_db_log_info() function while reducing to the max

I'm currently querying the sys.dm_db_log_info() DMV to retrieve the VLFs from a database to determine when I can shrink, reorganise and reduce the amount of fragmented (10 MB VLFs) in the TLOG file. ...
  • 15.7k
1 vote
3 answers
67 views

Finding the Second (time) Interval within X of the current time

I have a need to find, for a given current second and upper and lower boundary, find all of the seconds that would fall within that, wrapping at the 59 second mark. With that word salad out of the way,...
-1 votes
0 answers
18 views

Count rows with conditions from different tables

I am using postgresql. The database has the following model of entities and their relationships. I need to gather some requests statistics - the number of requests that are visible, the number of ...
  • 1
0 votes
0 answers
45 views

Resample time series in SQLite

I have following table: CREATE TABLE entries ( utc TEXT, entry INTEGER ); with following data: INSERT INTO entries (utc, entry) VALUES ('2022-10-01 01:54', 23), ('2022-10-04 02:40', 46), (...
  • 111
3 votes
1 answer
206 views

Valid for WITH clause to use existing table name?

Suppose I have a table Entry. Is it valid for a WITH clause to replace the Entry table for the duration of a query? I tried with SQLite and MySql and it seems to work, but I want to be sure this is ...
  • 133
0 votes
2 answers
27 views

Filtering Data on VARCHAR data type

I have a column. The data type is VARCHAR2. What I am trying to do is write a query to catch only the records that contain a string either in the beginning or end or in the middle. Below is a sample. ...
0 votes
1 answer
45 views

Compare table datetime, SQL & SSIS

I am trying to add a step in my SSIS job where it checks a table (FYI, so this table has only 1column which is a datetime data type that gets updated daily with a datetime from another table) whether ...
0 votes
1 answer
32 views

Why cannot I reference the second alias from a subquery containing a UNION?

Why cannot I use Qty2 as an alias in my query? I receive this error: Error Code: 1054. Unknown column 'qty2' in 'field list' SELECT mat, qty, qty2, SUM(qty), (ifnull(SUM(qty - qty2),0)) as TotalQty ...
0 votes
2 answers
38 views

How to query 30k of entries from an external data source by script

I have a SQL query which works for single checks: SELECT trans_id from schema.table where trans_id like '%<trans_id>%' There're might be better approaches to query for, but that's not the point. ...
0 votes
1 answer
52 views

How can I perform a join using a concatenated field? [closed]

I would like to know how to approach performing a join using a concatenated field. I have one table Task that has a value User. I want to join the Users table which has the value Logon the inner join ...
  • 37
0 votes
0 answers
38 views

Mysql parent child to pivot table

I want to convert my parent child table to pivot,below is my query CREATE TABLE parent_child with recursive cte (id, name, parentid,level) as ( select id, name, ...
1 vote
2 answers
101 views

Disable all triggers in a database

How do I disable all triggers in a database from another database which are currently enabled .And then enable it back only the ones I disabled .
0 votes
1 answer
26 views

How to UNPIVOT an aliased query result using PHP and MySql

I would be grateful for your assistance in helping me get solution for my project weather query problem. I have arrived at the query below and is working: "); $first_row = true; while ($row = ...
  • 13
-2 votes
1 answer
95 views

Loop through a row in a column and stop when the difference between the current row and previous row is greater than 1

How do I Loop through a row in a column and stop when the difference between the current row and previous row is greater than 1. E.g. (2022-02-06) -(2022-02-04) =2 which is greater than 1. So, I want ...
0 votes
1 answer
27 views

Filtering query results using combined columns

Not sure what this method might be called I have a table Pupil Payments Price PupilA 100 100 PupilB 100 50 PupilB 100 0 PupilC 100 20 I am running a query as follows SELECT Pupil, SUM(Payments), ...
  • 117
0 votes
0 answers
30 views

MySQL query: multiple select with different conditions and LIMIT for each, but also LIMIT whole query + paginator friendly

I would like to write SQL query (for MySQL) that is able to SELECT x rows by condition1 from table1 y rows by condition2 from table1+join1 z rows by condition3 from table1+join2 But on every page (...
  • 1
0 votes
1 answer
25 views

Joining tables with Union then adding artificial Column

I Have joined 2 tables together using union as follows SELECT DateTime AS Date, Pupil, DateTime AS Time FROM tableA Where Status = 'Pending' Union SELECT DateTime AS Date, Pupil, DateTime AS Time FROM ...
  • 117
0 votes
1 answer
26 views

Select entries with today and tomorrows date

I am using MariaBD and am trying to filter entries with todays date and tomorrows date. I have managed to filter todays date using SELECT *, DateTime AS Time FROM table where status = '...
  • 117
0 votes
1 answer
35 views

Access Search Form is not including null values

Sorry if this is an overly easy question, I don't use access often but was asked to make a search form for a table our company uses to track remake parts. I have a form created with a series of ...
-5 votes
1 answer
48 views

How to get second last record from table using subquery [closed]

I have more then 1000 rows want to get records using subquery, Remember not using offset or limit.
0 votes
0 answers
64 views

Procedure updating table with CLOB data type column does not work properly

I have a table with below structure: create table bb_analysisitems_batch ( batch_id number, batch_name varchar2(100), batch_result clob ) There are other ...
  • 1,376
2 votes
2 answers
65 views

How to order by cumulative value?

In my application widgets move step by step through a workflow. I want to list the widgets ordered by their step due-dates but I can't figure out how to do that. There are many workflows. Each ...

1
2 3 4 5
29