Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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).

0
votes
1answer
17 views

Subtract values in same column from 2 different dates in same Mysql table

I have a MySql table like: Item Date Likes Book 2012-05-20 402 Book 2012-05-21 432 Book 2012-05-22 450 Pen 2012-05-20 20 Pen 2012-05-...
0
votes
2answers
20 views

How to set all auto increments to 1 in a Schema

Is it possible to reset all auto increment in a schema in one query? if not even just by per table will do. btw I am using MySQL server 8 thanks in advance :)
0
votes
2answers
27 views

For states (col) receiving exactly X number of items (row), sort the items by weight (col)

I have been trying to figure this out for a few hours now but haven't gotten it. Each row in the table is a package. I am able to get the States with the exact number of packages, but don't know how ...
0
votes
0answers
22 views

How do I set up a query for Google sheets? [on hold]

I've got a sheet which contains the results of a google form. Column A contains a timestamp, B an ID, and C an integer value. Time,ID,Value 3/16/2019 x:xx.xx,0001,x 3/16/2019 x:xx.xx,0001,y I want ...
0
votes
0answers
10 views

Group json data in db using a query

I have a db whose values are as follows:img Can I call the json value of listing_id(23,27....so on) in properties column(with having row value as "listing") using a single query, I would Really ...
0
votes
1answer
12 views

List population of provices (SQL Query)

I was asked this question in an interview and I could not get my mind around it, and now it is bothering me a lot! If you have a table CANADA(PROVINCE, CITY, POPULATION). - Population is correlated ...
0
votes
1answer
16 views

Get percentage from results from two case results

How i can get percentage from two resuts from case staments? SELECT *, COUNT(CASE WHEN estado_rep >=11 and RELATION=1 THEN 1 ELSE NULL END) as pendiente, COUNT(CASE WHEN estado_rep >=...
0
votes
1answer
29 views

combine two select queries?

I have two Mysql select queries: select TTS.SSML, TTS_TAG.SORTID, TTS.VoiceId , TTS_TAG.TAGID FROM TTS left join TTS_TAG on TTS_TAG.TTSID = TTS.TTSID where TTS.MID = 15 select max(TTS_TAG.SORTID) ...
0
votes
1answer
22 views

Combing two queries in one

I have two tables, e.g. "Locations" and "Connections" "Locations" has values Id | Dimension --------------- 1 | 4 2 | 8 3 | 2 "Connections" maintains attributes Origin | ...
0
votes
1answer
25 views

Postgres select join json querry

I have a problem to make a postgres query with join from data of json. I have 2 tables the first one is media: id as integer path as string and an other table playlist id as integer media as ...
1
vote
1answer
43 views

How to search id from one table in another table's nvarchar column

I have 2 tables table1 ( id int, name nvarchar) table2 ( pid int, parameters nvarchar) parameters in table2 contains table1.id in nvarchar format, like "some text 12345 some text", where 12345 is ...
0
votes
1answer
15 views

Issue with Maximo KPI Returning “0” Instead of a Calculated % [closed]

I am attempting create a KPI in Maximo that will count the work orders completed on time and divide it by the number of work orders due for the current month, then multiply it by 100 to return a ...
2
votes
1answer
29 views

JOIN Call table to grouping by Origination and Destination

It's a call system. tables structure and data sample : tbl_countries CREATE TABLE tbl_countries ( country_id int(11) PRIMARY KEY NOT NULL AUTO_INCREMENT, country varchar(100) NOT NULL ); ...
0
votes
1answer
18 views

Batch query a lot of MySQLdump files

I have a website for an event. I set up a cron job to back up the database every hour. The backup command is mysqldump -u"$DB_USER" -p"$DB_PASS" --database "$DB_NAME" >"${OUTPUT_DIR}/${DB_NAME}.$(...
1
vote
1answer
21 views

How to count more than one time with different conditions?

Having a table like this: I want to get a result like this: Something like: SELECT ParentId, COUNT(SomeValue = 1) [CountMin], COUNT(SomeValue > 1) [CountRest] FROM MyTable GROUP BY ParentId
0
votes
0answers
8 views

Query getting data from another query triggers that source query or uses cached data?

In MS Access a Query Q2 can be so simple as SELECT * FROM Q1 (or largely complicated). Since Q1 can be another Query instead of a Table, the question arises. Does running Query Q2 trigger Query Q1 ...
0
votes
1answer
43 views

SQL Split Address Line into Separate Columns

Whats the best way to split a comma list column into different columns? I am looking for a simple algorithm, heard it is best to avoid scalar value functions, as they might be slow. Searching into ...
-1
votes
0answers
13 views

repalce query with left join and not in

i write a query with NOT EXIST like this > select id_request,username_request from darkhast_follower where > darkhast_follower.id_request != '9762952594' AND > darkhast_follower....
0
votes
1answer
26 views

Can I compress two rows with a difference in two columns into a single row with both columns?

I have a query that returns customer product information that shows which region a product is sourced from. Query: SELECT prod.prod_id, prod.is_source, link.prod_link_disabled, ...
0
votes
2answers
24 views

how do I get extra fields with in a column with calculations

I have a table AR--X with columns as Region, Product type, pofit, Target, 1, 2, 3,....... till 31 ( days ) as columns. In Product type Column, there are fields like Electronic, Plastic, wood, other, ...
0
votes
1answer
42 views

How to collapse into a single row from multiple rows

Please refer to the attached screenshot for the requirement. I have to collapse rows into a single row with latest test_date in one column and second_latest_date in an other column and latest ...
1
vote
0answers
23 views

How to exclude query results based on a blacklist

I have defined two tables: CREATE TABLE `devices` ( `uuid` varchar(256) NOT NULL, `token` varchar(256) NOT NULL, `last_connected` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, ...
0
votes
0answers
34 views

Match and update records in a table

I have two tables table1: | id | A | B | C | date1 | date2 | |-----|------|-----|------|--------------|--------------| | 1 | 100 | 100 | 100 | 10-Jan-2019 | 11-Jan-2019 ...
0
votes
0answers
32 views

DB Structure and Search with weighted ratings

Let's assume the following structure. For each pair of item and category we have a rating (between 0 and 10) item_id | category_id | rating --------+-------------+------- 21 | 31 | ...
1
vote
1answer
26 views

SQL Outer Join while conditioning on an extra column

I am trying to pull up an outer join between two tables, on a specifc column "Identifier", however, I would only like to carry out the outer joins on the rows where additional column "Date" matches ...
1
vote
1answer
19 views

calculate days spent of all visitors from encounters

I have an encounters table CREATE TABLE visitors( id serial PRIMARY KEY, start_date TIMESTAMP NOT NULL, -- visitor_id bigint NOT NULL -- skip for now, end_date TIMESTAMP ); (end_date can be ...
0
votes
2answers
21 views

Postgres Procedure Returns Table

We have a table structure returned by this function: RETURNS TABLE (ticker VARCHAR, current_recommendation INTEGER, previous_approved_recommendation INTEGER, ...
0
votes
2answers
40 views

Select records with the same first column value and different second column value? SQL Server

Assume we have a SQL Server table as the following: ContentId | TagId -------------------- 1 2 1 3 2 1 2 2 2 3 1002 1 ...
0
votes
1answer
25 views

How to delete all but the latest entry per customer in the fastest way?

I have a table containing around 4 million unique customers (with customerId each), but each customer can have multiple entries. There is no primary key. Each row has a creation dateTime saved as ...
0
votes
0answers
12 views

How does query parameters work under the hood?

I thought about how can it work under the hood and I came with an idea Db engine receives query with parameters and also defined values of those parameters SQL is being parsed into syntax tree like ...
2
votes
2answers
27 views

How can I position the element generated by XMLTEXT in a FOR XML query?

I'm trying to use FOR XML to simulate an OData feed. One of the requirements I have is that somewhere I need an XML element which is constant for all records; I was planning to use the XMLTEXT ...
1
vote
1answer
37 views

Select one record from LAG Query

I'm having difficulty getting data from a query using the LAG method. The issue is that I only need one record from the entire set pulled down, but when I filter out that record in the WHERE clause it ...
1
vote
1answer
39 views

Unexpected Row of Data when Joining two tables

I want to join both tables, and its giving me a much harder time and it should be, at least it doesn't look that complicated. Would be easier if table b would have a value for ID: 0, but it doesn't. ...
1
vote
1answer
54 views

Number of rows summed up by grouping them, each group has a different number of rows

Every 4 rows need to be summed up and displayed against that group but every group has different number of rows, at the end of the group for the odd rows sum is different. For example, in the group ...
2
votes
4answers
181 views

Include all possible values of sub-categories under each category

How can it be achieved in MS SQL 2016, when I need to always see every state under all existing categories even if there are no records, which satisfy the state formula? Under a and b below I always ...
0
votes
1answer
24 views

How can I search for a hex string in oracle?

There's a database record that is incorrect. The name field displays like this in a browser ( this is incorrect ): Thcˇodore And when I look at the record via SQL results, I see: Thc\xCB\x87odore ...
1
vote
0answers
34 views

Using conditions to return specific rows

From the following table i am trying to retrieve specific rows based on a criteria +----+--------------+------+ | ID | UPDATED_DATE | TYPE | +----+--------------+------+ | 1 | 01/13 | P | |...
0
votes
2answers
33 views

Run query against all databases on server containing specific string in name

If I have a query such as: SELECT convert(varchar, DateTime, 100) AS "Date and Time" ,Text2 AS Area ,Substring(PText7, 1,Charindex(':', PText7)-1) AS Username FROM the_database.dbo.AlgViewENU AS data ...
0
votes
0answers
27 views

Help with query to assign conversion

I would need help with my SQL foo. I have 3 tables like this TBL LEAD id email activity_tracking_id ... TBL ACTIVITY_TRACKING id uid created_ad action referer ... TBL BUYERS id email ... Table ...
1
vote
1answer
48 views

How do I join these two tables, showing results from the second table? [closed]

I have two tables and I want the following result: if CID and CID2 are equal, print cpu about value of CID2. Table A: +------+---------------------+--------------------+-----------------+ | CID | ...
0
votes
0answers
29 views

How to improve query performance through denormalization of this schema or other techniques?

My database attempts to describe some items, their sources and a variety of restrictions on who may use them as well as a number of intrinsic properties about the items. It looks a little bit like: ...
1
vote
1answer
42 views

Alternate to use LIMIT in subquery in mysql?

I have 2 tables, Resource and views and I'm trying to get the list of all the items from Resource table whose ran_resId don't match with the ran_resId of last 2 records of views table. I'm trying to ...
1
vote
1answer
36 views

Handle 4 tables and to show 4 columns as result

i can't figure out how to build the correct query that involves 4 tables and shows these 4 columns: I want to show this 4 rows, each from a different table. EDIT: Each company belongs to a Sector. ...
0
votes
1answer
28 views

How to query database tables structures for DATE NOT NULL DEFAULT '0000-00-00' and ALTER them in MySQL

I am using MySQL v.5.7.x. In a database with 161 tables, one of the them has the following structure: CREATE TABLE `prefix_coupon` ( `coupon_id` int (11) NOT NULL AUTO_INCREMENT, `name` varchar (128) ...
0
votes
2answers
26 views

Query to insert data into columns and check for pre-existing values for those columns data

I have table t1 and t2 with same column names in both tables, column a and b. I want to enter data of column a and b from t2 into t1 at the same time check weather any data pre exist in t1. If data ...
0
votes
1answer
40 views

Is it possible to rewrite this Function for optimization?

I need help optimizing this function as it takes more than 2 minutes currently which is far from optimal. This function basically gives you the name of column, corresponding table and list of unique ...
0
votes
1answer
32 views

Get full tree hierarchical query

I want to get all data of tree by ID. My table is: ID NAME PARENT_ID ------------------------ 1 A NULL 2 B 1 3 C 1 4 D 3 5 E 4 6 ...
0
votes
2answers
26 views

Join queries are not working as expected when trying to compare a count result with a value

I'm learning SQL from a book and I'm trying to do some exercices on join queries. The only problem that I'm facing is that all of my join queries are not working while they seem well. These are the ...
0
votes
1answer
43 views

How to search multiple values using LIKE

I'm using MySQL and I have a table with these fields : id name kode_fakultas year I want to create a form for searching based on user input. Example, if the user search is based on name, but the ...
0
votes
2answers
45 views

Writing SQL to check for a role if exist and add member [duplicate]

I am not to good at writing SQL so please help with below as i am doing something wrong here I need to alter a role say role_a to add member Domain/SQLAgent The problem is how can i check or write a ...