Questions tagged [select]

A core SQL statement, SELECT retrieves data from one or more tables or other sources of row set data such as views or table-valued functions.

Filter by
Sorted by
Tagged with
0
votes
1answer
15 views

Additional Select statement within Cursor terminates looping unless Select statement returns a results for all cursor rows

I have a simple database called 'held_toys' (a held toy is a toy which is not on sale yet) which is comprised of a primary key and a foreign key for a Toy. I have a second table called 'toys_on_sale' ...
0
votes
2answers
41 views

How to select all columns plus one alias column in MySQL

It is a simple question, but i could not find the answer. I want to select all the columns in my table with a SELECT * statement, but i also need to alias a UUID column this way: BIN_TO_UUID(ID) as ...
0
votes
1answer
37 views

Omit table name and dot in SELECT query

When I perform this query: SELECT `tablename`.* FROM `something`.`tablename` I get a table with column names that contain dots: tablename.c1 | tablename.c2 | tablename.c3 ---------------------------...
-2
votes
1answer
18 views

Can't manage to work with comparing days

In a table with persons and their birthdays, the ones whose birthday is in less than 7 days need to be displayed. I found some answers on the Internet but they all are at least 5 years ago with ...
0
votes
2answers
80 views

Why is this SELECT creating temp tables?

When I run the following SELECT, it takes quite long, typically 30 or 40 minutes (I'm on Debian, MySQL 5.5.62): SELECT ga.currency, o.organisation_name, os.hostname, g.global_name, SUM(IF(ga....
-1
votes
2answers
28 views

Select Rows From One Table, Where Matching Rows in Another Table Has Empty Column

I have multiple Postgres tables that look like the following. They are generated on a daily basis, so each just represents the data that was processed for that day: data_20200113 +-----------+-------...
0
votes
1answer
18 views

How can I find the difference between queries that return multiple rows?

I have two tables, website and page, that look like such: website id | name ------------ 1 | site 1 2 | site 2 3 | site 3 page id | name | site_id | deleted ---------------------------------- 1 ...
-3
votes
0answers
14 views

mysql str_to_date() produces invalid timestamp?

(MySQL 5.5.62) Am I doing something wrong here? I want to convert a string to a TIMESTAMP: mysql> select str_to_date('2020-02-01 23:59:59','%Y-%m-%s %H:%i:%s'); +-----------------------------------...
0
votes
1answer
60 views

how to find min max of sum?

hello everyone i try to find minimum and maximum value of SUM(units_sold) i test some ways but i can't find best solution please help me ! SELECT TOP 1 dp.product_name, SUM(fs.units_sold) AS ...
-1
votes
3answers
49 views

Query for showing missing years

I have a question about showing the missing values by a query. Given table named Top2000 with fields Artist, Title, Ranking, Year, the following query... Select * from Top2000 order by Artist, ...
0
votes
0answers
33 views

Use SELECT query to retrieve UPDATE information

I am confused about inability of using UPDATE query inside SELECT queries. I got this idea, it would be amazing to use queries like follows for elegant reporting purposes My non-working code: SELECT ...
0
votes
1answer
30 views

current_timestamp at time zone 'UTC' SQL Server equivalent

What is the equivalent of the Postgres "current_timestamp at time zone 'UTC'" in SQL Server? How do I select the current timestamp in UTC in SQL Server?
0
votes
1answer
22 views

Select one of multiple columns into a new column Ask Question

My database table looks like table 1 below: Table 1: +----------------------------------------------------------------------------------+ | id | distance | duration_sec | speed | foot | ...
0
votes
0answers
56 views

Oracle DB divide by almost smallest number ever

Oracle DB 11 or 12. Got this code: select 1/0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 from dual; That's ...
1
vote
0answers
74 views

Grafana - combine multiple SELECT from different measurments

I'm totally new here, I tried to find solution and I found this: Influxdb and Grafana combine multiple SELECT but this works fine if we have different fields from the same measurement, but this ...
0
votes
1answer
20 views

Finding Conflicting Combinations Using SQL

Say I have table called "Everyone_Loves_Relationships" which contains three fields: Boy_Name, Girl_Name, Relationship_Status. The list goes like this: Boy_Name Girl_Name Relationship_Status Tony ...
0
votes
0answers
21 views

Word file running an SQL command - How do I find the source SQL database?

A word 2013 file has a merge function that activates whenever this is open and it is "SELECT * FROM 'database'". As the final results have errors (the final word document feeds from the wrong field ...
0
votes
0answers
22 views

Oracle: Select values and join result from multiple rows in one with seperat cells

I have to create a select Statement, which bring me a multiple row result in one. For better understanding here my table Id | Name | Typ | Date --------------------------------- 1 | John | ...
1
vote
2answers
29 views

How to get sum of 3 sub count queries and group them using an attribute

I have 3 queries as follows: For the date 2019-12-02, I am calculating 3 type of values. The total value for 2019-12-02 must be the sum of these 3 queries. Q1 SELECT count(*) FROM ...
0
votes
1answer
32 views

select subquery condition in where statement

I am getting this error: ORA-06550: line 43, column 16: ORA-00904: "STOCK_BALANCE": invalid identifier ...for the following query: select PARTY_ID, PARTY_NAME, IT_ID, IT_ID ||...
0
votes
1answer
17 views

SQL: Select all items and add info from left join where condition is met

Background I am creating a news site. Table NEWS has all news with unique ID news_uid. TABLE NEWS -------------- news_uid | ... If a user has read a certain news, that info gets stored in table ...
-2
votes
1answer
29 views

Reusing calculated value in mysql select statment

I need to reuse once calculate variable again in my select statement. Is there any way to acieve it? SELECT user_id, SUM(duration) as loggedhours, COUNT(DISTINCT(DATE(timestamp_start))) as ...
-1
votes
2answers
54 views

How do I select specific columns in a sql prepared statement?

I have created a prepared statement to output a file and add a date to the filename. That part works if I select the entire database. I want to select specific columns to include in the query, not all ...
3
votes
3answers
400 views

Mysql - Average price for top 10% cheapest volume (algorithm help)

My question is very similar to this but not the same. The table is the same: rows with ID, volume, and price. In short, I need an SQL query that will give me the rows with the lowest prices whose sum ...
2
votes
1answer
47 views

UPDATE column to MIN of a SELECT result set - what went wrong?

I've got the following scenario: I've got a table of assets with standard columns a table of hardware assets with extension columns a history table where all changes to an asset are stored with ...
0
votes
1answer
22 views

Use plpgsql to count records selected for output AND output those records

My query SELECTs 1 row from table1, which has a number of fields plus one very long text field. It JOINs with a second table2, that may have many matching corresponding rows. I would like to be able ...
2
votes
1answer
26 views

Select IDS where all values can't be found in another table

Hey I'm pretty new to SQL and I've come up with a problem that I haven't been able to solve I'm trying to make a query to bring up ID's that have ALL null values and are located in another table. DB ...
0
votes
0answers
17 views

How to fetch different record when nothing matches in where conditions in the same query?

I am using ORACLE 12C database. There are two components - Agreement and Case. Agreement related information stores on Agreement_line and Object Table. Common column between these tables are ...
0
votes
2answers
64 views

MariaDB FULLTEXT search with apostrophe, and mandatory words

An apostrophe / single quote (') should be part of a word in a FULLTEXT index. Admittedly I can't find this on the MariaDB website, but I'm assuming it should still behave like MySQL (version 5.5). ...
0
votes
1answer
11 views

Need postgres statement that returns non unique records even if I pass same ids in array

For Example, the following query SELECT id, name, price from tennis_ticket where id=ANY('{3,3}') returns: id | name | price ----+--------------+------- 3 | Eighty | 80 (1 row)...
0
votes
1answer
24 views

Select with a preffered where condition, but if missing use another

I have the following select in SAP HANA DB: SELECT name, text, lang FROM texts WHERE name IN ('name1', 'name2', 'name2') AND lang IN ( 'S', 'E' ) INTO TABLE @DATA(lt_texts). It will select ...
0
votes
1answer
29 views

How do I check three conditions on a select with one query?

I have a table containing email text for welcoming new users. There is a default email, one that may be client_id specific and one that may be user_id specific. I can do three queries to find user, ...
0
votes
1answer
20 views

distinct description

I have the following database: id | remote_id | title | description ------------------------------------- 1 | 12341234 | test | test-description 2 | 4535234 | blah | testestetetst 3 | ...
-1
votes
1answer
54 views

How to optimize a slow select query with tuples in WHERE clause

I am currently trying to optimize a select query which takes 5-10 seconds on tables with 50k rows (and will grow 100x this soon). The purpose of this query is to find which tuples from a given set of (...
0
votes
1answer
23 views

Converting ticks into range bars

You have a tick table with 3 columns CREATE TABLE tick ( symbol character(9) NOT NULL, price real NOT NULL, "time" timestamp with time zone NOT NULL ); INSERT INTO ...
1
vote
1answer
28 views

Generate hierarchical path

I have a classstructure table: create table classstructure (classstructureid number(8,0), classificationid varchar2(25), parent number(8,0)); insert into classstructure(classstructureid, ...
1
vote
2answers
30 views

Aggregate results from select queries

I have a table with three columns: id, date, state. For each unique value of id, I would like to select date and state, multiply the state array by a scalar variable for each id defined from else, ...
0
votes
1answer
61 views

Mysql query to find last entry for each of the last 7 days

I have a table that contains a timestamp and a number for each row. This data is logged every 15mins on the quarter hour, 24 hours a day, but it does sometimes get missed or is delayed. I'd like to be ...
2
votes
2answers
350 views

Select previous value in row without using a subquery [closed]

Say you have a table in PostgreSQL 11 with sets of values something like this below. 12 18 11 12 5 12 9 18 7 19 14 18 11 16 6 12 4 11 5 9 Is there a way to do a select without using sub-...
0
votes
2answers
30 views

Group results from two different tables on same hours

I have two simple tables: indoor id | timestamp | temp | humi outdoor id | timestamp | temp And two selects which give me time and average temperature grouped by same hour for the last 24 hours: ...
0
votes
1answer
65 views

How to access Multiple DB2 Relational Databases In A Single Query

I need a solution for below: There are Two DB2 instances with two authorization ID on the same server and can be access using same user User1. Example: To access Inst1DB, I use the following ...
0
votes
1answer
28 views

Postgres/PostGIS is returning data from a table that doesn't exist (I'm a newbie — show me why I am wrong)

I am following a tutorial for PostGIS. I have uploaded all the example datasets (all shapefiles) into a PostgreSQL database, although I have modified the names so they do not all match the names of ...
1
vote
1answer
36 views

Get normalized representation of SET datatype

In MySQL you can SELECT SET values from a table using this syntax: CREATE TABLE `test_set` ( `int` int(11) DEFAULT NULL, `set_2` set('a','b','c') DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=...
5
votes
2answers
944 views

Unable to output data from tables in pgAdmin4 due to missing oid operator

I am currently running Postgresql 10.6 locally which I interface with using PgAdmin 4.12, up until today everything was running fine. However today I ran the following query in the pgAdmin query ...
0
votes
1answer
58 views

Postgresql, case, select in when

System PostgreSQL 11.5 (Ubuntu 11.5-0ubuntu0.19.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0, 64-bit Case Does select work in case condition? I need return 1 state ...
0
votes
3answers
103 views

Select youngest record

I have a MariaDB table "mdata" with the following schema: +-----+-----------+---------------------+------+ | id | room | date | temp | +------+-----------+---------------------...
0
votes
2answers
25 views

Count two different columns from two different tables and throw into a single variable

I have two tables in my project: "cats" and "items". Every single item in "items" table has the value "item_cat" (column), which represents the ID of actual category, where that item is assigned to. ...
0
votes
1answer
26 views

How to get the customer payment count for each row in MYSQL

I have a payment system, and want to display the counter of each customer payment (first, second, third ...) and if it's the fist payment, display (New). How can i do this in one query ? SELECT c....
3
votes
1answer
93 views

Selecting rows conflicting values in WHERE clause

I am having trouble selecting rows in MySQL. I do not want some rows to be selected, but they are being selected. My query: SELECT name,url FROM additions WHERE enabled = 1 AND ...
0
votes
0answers
37 views

How to retrieve all children of a parent record?

I have one MySQL table with this columns: id father son street city I want to obtain all descendants of a father recorded, how I can do this? I tried this: WITH RECURSIVE filhos AS ( select login, ...