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
-1
votes
0answers
5 views

How do I use PHP to construct an SQL query to sort and select from multiple rows in my database

I'm building a game using a platform called Unity. The game integrates with some php scripts and a database I have. Players can register in the game and all info gets stored in the database, including ...
0
votes
2answers
19 views

How to get count of each column data

I am trying the fetch the data of the each user of each month. The table looks like below ---------------------------------------------------------------------------------- | user | pm_jan ...
0
votes
2answers
26 views

Create a row based on a condition (column value)

I have a table that contains the following data; EmpNo | GivenName | PreferredName --------------------------------- 1 | Paris | Paris 2 | Ashley | Ash I am trying to get an output ...
0
votes
0answers
16 views

Date between intervals dynamic

I have a table with all employee licenses and two dates in relation to a period of 2 years. I have to verify if have someone period sum of 30 days of license in one range 12 months For example: data ...
0
votes
1answer
63 views

Sql, get category tree for values from one table, names and ids

What I need I need select all ids or names from table "category" (all chidrens) until category_id is 0 (main category). Example On web there is product with category tree. In table "category" I have ...
0
votes
2answers
22 views

CHARINDEX equivalent in DB2

I am trying to select the domain from the column where I have email addresses. For example, I have a table email_table and a column email with email addresses as below. johndoe@gmail.com jhefid@...
0
votes
2answers
21 views

Get matching part from conditional pattern

I'm having a table like this: |id|key |value | ------------------------ | 0|name |Homer | | 1|surname|Simpson | | 2|town |Springfield| I'm running this query: SELECT * FROM ...
0
votes
2answers
37 views

How to select top 3 vendors without duplicate entries?

Here is my tables I want to select Top 3 lowest quoted rate vendors without duplicate Entry. Expected output will be V1, V4, V3 without using while loop. is this possible? Table details CREATE ...
0
votes
1answer
31 views

Select query with custom column and value of other column

I want to have a query that have a custom column and have some value of other column here is example of a table table 1 : id, name, emp_id I want to have input like this id | name | emp_id | ...
2
votes
1answer
39 views

How to use grouping sets in this query that shows database sizes - adding the last time it was updated

I have the following query that shows me the database sizes, including log dna data files. SELECT [Database Name] = DB_NAME(s.database_id), [Type] = CASE WHEN s.Type_Desc = 'ROWS' THEN 'Data ...
0
votes
1answer
25 views

Postgres DB is extremely fast with a query with a certain parameter, but extremely slow for another

I have a table called stats, where I store every action on a certain website (basically when the user clicks a link, data is saved in the db). The data is modeled with PostgreSQL as ( id integer NOT ...
0
votes
0answers
24 views

distinct inside COUNT() OVER()

The query shown below has line COUNT(*) OVER() totalitems that returns total number of rows and rows are ordered by 'numero DESC' SELECT * FROM ( SELECT a.*, ...
6
votes
1answer
82 views

Tree Node Calculation - SQL Server

I'd appreciate some help with something I am trying to achieve please. The parts that my company make are built from sub assemblies and sub assemblies of sub assemblies. This looks like: ...
0
votes
1answer
21 views

Is there a way to search the earliest or latest postgres partition for table?

BACKGROUND I am working on a web application that has date pickers for searching. Those searches query a partitioned table. So far, so good. However, based on the data I'm querying, we don't have a ...
2
votes
2answers
31 views

How to find exact string from a sentence

I'm using SQLITE and I'm trying to find the exact word on a sentence, but I'm not getting just the word I'm getting for instance if I'm looking for Water I'm getting also aWater, wateri24 and that's ...
0
votes
1answer
27 views

Listing IDs that match values in two columns of a table

I'm using SQLite 3.27.2-3 on Debian Buster/stable. I could use some other DB, but for my use case (LuaTeX), something with low overhead seems to make sense. My use case is that I have a letter (in ...
1
vote
2answers
34 views

Multi query with group by , join them in different columns

One table has different columns for each column I want to do a group by function. I get unique values for each column in the table. Origin Table data: +----+--------------+--------------+ | id | ...
0
votes
0answers
16 views

Select rows that are referenced in another table and if not return NULL [closed]

Tables: CREATE TABLE `books` ( `bookID` int(11) NOT NULL, `title` char(255) NOT NULL, `datepublished` date NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `authors` ( `authorID`...
0
votes
2answers
85 views

split one column into two columns based on it's value using t/sql

Hope you're doing well. I have a table as you can see below : ACNTHEADER(DDATE DATE ,ACNTCODE INT,VALUE NUMERIC(17,2)) the data in the table : DDATE ACNTCODE VALUE 6/1/2013 1174 ...
2
votes
1answer
59 views

Separate a column into its components based on another table

I'm struggling with a very difficult and complicated query here and I need your help. I have two tables as you can see below: 1) ACCOUNT1:(ATYPCODE int, ATYPDESC varchar(50), ATLASTFLAG varchar(50)) ...
0
votes
0answers
22 views

Building and Executing a Query Execution Plan Manually in PostgreSQL

An SQL query goes through multiple stages to be executed. This is a wide topic, but in summary, multiple execution strategies are proposed for each query, they are evaluated, and one is selected for ...
-1
votes
2answers
23 views

Query to collect the recent unique TimeSampled rows using inner joins for multiple servers in MS SQL [duplicate]

Dears, I have written below inner join query to get the data from my database tables. But output of this data is coming up with almost 3k lines. Output is below. I need data in only unique recent "...
-2
votes
0answers
13 views

Help calculating overtime based on M-Sun but also between 1st-15th and 16th-EOM

We calculate out time cards for pay on the 1st-15th and 16th-EOM.. In Utah our overtime is figured on a weekly basis of Monday - Sunday over 40 hours. If an employee has over 40 hours during this ...
1
vote
1answer
32 views

Create a function/tsql to get strings from the 1st table/data and compare and convert if from the value of second table

I want to create a function/tsql to get strings from the 1st table/data and compare and convert to the value of a second table if the strings match what is on table 2. Business example. When a ...
0
votes
1answer
26 views

How to create two additional columns in a results set to act as axis for a heatmap

I have a set of results from a WSUS report that consists of computername and the status level of patching on that computer. I have been asked to display this as a heatmap e.g each computer is a ...
1
vote
1answer
19 views

Left join including nulls

i know this question might be dumb and might be duplicated. but im having a problem with my left join query. so please help Y.Y the output im currently is something like this judge name|score judge1 ...
0
votes
1answer
13 views

mysql select increment group row number

i had a table like following: OBJECTID FRUIT ---------------------------- XA13AC Apple HAS13X Grape UTHQ1G Orange YQ1GXQ Kiwi OQP1GV ...
-1
votes
1answer
28 views

how to get content from a TEXT column in mysql? [closed]

maybe dumb question but if I have a table with a MEDIUMTEXT column how do I query that table and see what the actual content is? eg SELECT text FROM PRIMARY_TEXT WHERE id = 1. What I get back now is [...
-4
votes
1answer
49 views

How to get count 0 using group by if record not exist?

I have sql server query and i want to get count=0 if record not exist. I want to show all from category table , show all categories with count 0 if not exist. But its return empty if record not exist ...
0
votes
0answers
8 views

ST_MapAlgebra count if full extent

I want to count MAX value from two rasters with different extent. I use this code: DELETE FROM vitr.pove; INSERT INTO vitr.pove (rast) SELECT ST_Tile(ST_MapALgebra(a_c1d1.rast, 1, b_c2d2.rast, 1, '...
0
votes
0answers
15 views

MySQL view extremely slow despite indexes

I'm having an issue with a view, when I make a query it brings CPU to 100% and it keeps loading. The view is: https://pastebin.com/ZgB7rr91 channel_data_60 table contains about 1,200,000 records: ...
1
vote
2answers
46 views

query help in joining tables

I'm quite green in mysql, but I have been assigned a task for which I completely lost. I have a unique codes table in mysql and then I have another 6 tables for individual clients. I would like to ...
0
votes
0answers
8 views

ERROR 1064: Cannot execute while loop in mysql using variables [duplicate]

I'd like to run the below query to insert into a table in a loop: SET @maxid = ( select max( length( id ) ) from article ) ; SET @x=1; WHILE @x<= @maxid DO INSERT INTO `article_responder` (...
3
votes
1answer
168 views

How to use JOIN and SUM function to Calculate the total of query returned column?

I ran bellowing query; Query: SELECT j.jobId, j.productId, p.productUnitPrice FROM JobRequiredProducts J JOIN Product p ON p.productId = j.productId WHERE j.jobId = 1 ...
0
votes
1answer
39 views

Slecting specific query returnned data related records from another table [closed]

Product table: productId | productName | unitPrice | supplierId _______________________________________________ 1 | Iphone8 | 1500 | 3 2 | Nokia 6 | 800 | 1 ...
0
votes
1answer
14 views

How to update a column whose value is being calculated from the values exists in other columns of same table in MySql?

I've a table User_Engagement having columns :- I was trying to implement this below formula on my update Query to calculate TotalInteraction of all columns in a single query:- totalInteraction = ...
0
votes
0answers
19 views

How can get each row of other table in 'where' condition?

[Table1] row, col1, col2, col3 1, 0 , 2019-06-20 09:00, 2019-06-20 11:00 2, 0 , 2019-06-20 11:30, 2019-06-20 13:00 3, 0 , 2019-06-20 13:30, 2019-06-20 17:30 [...
-2
votes
1answer
39 views

Help me write this query in SQL

I'm trying to get help writing a query from scratch SQL. Thanks Here is Question: Find email addresses dbo.[EmailAdresses] that are not associated with any person dbo.[Person]. Return [...
-2
votes
1answer
29 views

Help with correction of writing SQL queries [closed]

I have questions, but i never work with SQL before. Can someone help with queries? 1) "How many persons with Title = 'Mr' [1] have 'Purchasing Manager' type [2] of the contract [3]" 2) Find email ...
-2
votes
1answer
31 views

How to find out NOT NULL attributes in tables

I need a query that returns a list of attributes in a table that cannot be null.
0
votes
0answers
35 views

How to formulate a query and view for the following structure?

Consider the following table structure: TableA ColumnA ColumnB ColumnC Ro1 A 1 Ro1 A 1 Ro7 A 3 Ro2 C 1 Ro3 B 1 Ro3 B 1 ...
0
votes
1answer
41 views

SQL Alert for long running queries [duplicate]

I want to receive a mail when a query is running for more than x seconds. I know I can set up a job running on the database but, is there any way to do the same using SQL Alerts? What kind of alert ...
2
votes
2answers
45 views

Job Information - When querying [msdb].[dbo].SYSJOBS_VIEW through linked server

I am trying to build a report to query all my sql server jobs and thier status from the previous night's run. In an effort to have just one report instead of a separate report for each server, I am ...
0
votes
1answer
26 views

How to get dates from a table while the date range is from the date belonging to another table?

I have a table datedim which has all the dates of a month in it. I have another table attendance that has dates on which attendance were taken. I need to write a query where i can get all the dates ...
0
votes
0answers
33 views

Allocating Hours From Operations Table to Available Hours in Availability Table

I have a scheduling problem… The database is SQL Server 2017. The data comes from one Table and one View… Operations_TBL Operation_ID Resource_ID_Link Operation_Start_By_Date ...
8
votes
3answers
158 views

XML Query Question

I'm trying to generate a SQL query to get the "DATE" values out of the following SQL XML: I've tried something like this but I don't think I'm understanding the concepts. select xConfig.value('(/...
0
votes
0answers
65 views

Allocating Rows From One Table to Available Date Range in Second Table

I designed a Shop Floor Scheduling System and it’s been running well for years, but the managers are now asking for something more precise and what they are asking for puts me outside my comfort zone. ...
0
votes
1answer
66 views

Unable to use today's date as a criteria in a query

Ok, been a good decade since I've worked with Access and SQL, so a little forgiveness please. Short version - when I add the query criteria to only display rows which match today's date, the query ...
0
votes
0answers
6 views

Complex queries in CouchDB across multiple documents

I'm relatively new to CouchDB (more specifically Cloudant if it matters) and I'm having a hard time wrapping my head around something. Assume the following (simplified) document examples: { "docType"...
-1
votes
1answer
24 views

I need to create query connect 3 tables with Many to Many relationship in MariaDb

I have Many to Many relationship Tables. items, caregories, stock, item_category, item_stock Items: Categories: item_category: ╔════════╦════════════╗ ╔═════╦═══════════╗ ╔══...