Stack Exchange Network

Stack Exchange network consists of 174 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 [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.

0
votes
1answer
12 views

LEFT JOIN based on content of a field in matched rows

Generically, I'm attempting to take a table and join it with another table but only on rows that have a specific value in one of the fields. Specifically, I have a users table and a contact table. ...
1
vote
1answer
18 views

SQL How to show information from others tables in select requet

There are my database user id | user_code | user_name 1 | 1x2d | Peter shops id | shop_code | shops_name 1 | 1234 | shop1 2 | 3456 | shop2 articles id | art_code | art_name 1 | ...
1
vote
1answer
58 views

Select within or closest to date range MSSQL

Lets say we have a table CREATE TABLE [dbo].[Product]( [ProductId] [int] NOT NULL, [Name] [varchar](50) NOT NULL ) CREATE TABLE [ProductPrice]( [ProductPriceId] [int] NOT NULL, [...
0
votes
2answers
32 views

MYSQL search for each name in 2 columns and add values associated for each player

I have a database "game_results". It contains the following: PlayerID (int not null primary key auto increment) player1 (varchar) p1destroyed (int) player2 (varchar) p2destroyed (int) winner (...
1
vote
1answer
26 views

How to find maximum of average grouped by in sql

I have three tables Faculty {id, name}, Student {id, faculty_id, name}, Course_student {id, student_id, mark} And i would select top student in each faculty I'm tired to perform this in multiple ...
0
votes
1answer
83 views

Why select statement against a table in oracle returns ORA-04021

I have a big partitioned, local indexed table in Oracle database, what I am doing is import a big dump file into it with "impdp" Why when I issue a select statement against that table Oracle returns ...
1
vote
0answers
20 views

PostgreSQL update and select in one query [duplicate]

I have a table (id, serialnumber, status) of numbers and their statuses, need to take one with status 'unused' and change it's state to something like 'in work'. Can do it this way: UPDATE serials ...
2
votes
1answer
77 views

Filter on value in another row

Please see image of the data and my code so far. In this example I only want the first two rows to be retrieved. The reason for this is because where JobID is 1684 the sum of STILL_REQUIRED is > 0 ...
0
votes
2answers
35 views

SQL firebird dont select rows with 0

This works fine, except in the results, I don't want the rows where STILL_REQUIRED is 0. I am using firebird. Select ID, JobID, NAME, ORDERNUM, STARTAFTER, FINISHBEFORE, START_OFFSET_MINS, ...
2
votes
1answer
34 views

Select the same field based on different foreign keys

I have two tables: Containing a list of products with ids and names A table linking several products with parent-child relationship based on ids using foreign keys. I want to create a view that will ...
0
votes
1answer
29 views

Why is searching by one varchar column not working correctly on replica?

PostgreSQL: 9.6, master, replica. Async replication, wal archiving. We detected that if we execute a select query on a varchar column against a replica, then the results return no rows, but if we ...
1
vote
2answers
27 views

Showing data that is not already in the data base

I have the following problem. I want to search a query in an existing data base and that the result shows me the entries of the query that are NOT already in the database. Minimal example: | ID | ...
1
vote
1answer
16 views

Selecting only when specific values exist in another select query

A bit of a noob question, but would appreciate the help. I want to use the result of one select statement in a different one in a specific way. The first select statemnent: SELECT DISTINCT id FROM ...
0
votes
1answer
40 views

SQL, creating a new table with auto generated passords from other tables

i have this sql below which i have retrieved from our student database. It retreives all that i need, but i would like to create a new table which includes all the tables plus one column with auto ...
0
votes
1answer
21 views

How to get Row Value & Sum/ Aggregate in Same row? (SQL Server)

Just wondering if I have data like name score A 2 B 5 C 7 I would like to have a 3rd row name score total A 2 14 B 5 14 C 7 ...
3
votes
1answer
78 views

SELECT Parent-Child with SORT

I have a simple, one level parent child relation table, with following columns: ID_Asset| Parent_ID_Asset | ProductTitle I need output grouped by Parent followed by children, and also sorted by ...
0
votes
1answer
37 views

Select rows from table 1, table 2, then selecting based on ID

I am dealing with a large dataset, and have run into some issues because of this. I have a data set like: Table1 State ID Conditional_Value AZ 1 Yes AZ 2 ...
0
votes
1answer
16 views

MySQL 8.0 - SELECT QUERY

Hi I am having trouble with building a select query command with my tables. TABLE CUSTOMER +-----------------+-----------------+--------------+ | customer_number | customer_status | order_status | +-...
0
votes
2answers
70 views

Group by range DATIME of 2h up or down - Mysql

Well, I have a table with some columns that some of these are repeated, but the time is not exactly the same, I need to do a group by that has a range of 2 hours. Notice that all the fields marked in ...
-3
votes
2answers
37 views

Showing records with same last name but different first names with one of first names meeting a criteria

My SQL query is more complex than this but this part I am stuck. For example if I had a table: lname fname -------- ----- Mitchell Jason Miles Ryan Miles Mary Mitchell ...
0
votes
2answers
37 views

select single row from table for a particular column combination

I have a table as below Id... ColA... ColB... Isdefault 1... 100... 96... 1 2... 100... 96... 0 3... 101... 98... 0 4... 102... 99... 1 I want to ...
1
vote
1answer
29 views

Oracle Subselect Union Multiple Column

I want to select and count all cats and dogs at one location; location | cats | dogs | new york | 150 | 66 | paris | 34 | 12 | What I've got so far: SELECT cats,dogs FROM (select ...
1
vote
1answer
27 views

Select with inconsistent linkage

I have a table with three columns (ID, ReviewToId, ReviewFromId) I would like to get record with the ReviewToId and ReviewFromId is not Consistent For example, with pic attached: I would like to ...
1
vote
0answers
25 views

MySQL count rows of multiple tables for each user

I basically need this with some adjustments, I just can't seem to figure it out how to do it. I need to sum the rows of two tables, for example: SELECT student.StudentID, student.`Name`, COUNT(...
0
votes
1answer
35 views

MYSQL REPLACE string content with field value

How can I REPLACE a string value with a other field content? SELECT REPLACE(html_input,'!value',field_value) FROM table Value of html_input is <input type='text' value='!value'> Value of ...
0
votes
1answer
46 views

What is the best way to check if a value in a table has changed when writing to a database?

Let me provide you with an example. Let's say I have an html_tag with two columns, tag_type and tag_value For example, let's say I have a record with the value "link" under thetag_type field and "...
2
votes
2answers
39 views

Return values as 1 or 0 together with percent

I need a SELECT that will result in a percentage and columns with 1 and 0 for exist or not exist. The goal is to generate data for a usage meter (Percentage 0.0-1.0) and each measurable value as 1 or ...
1
vote
0answers
91 views

Oracle 11g Select query returns NO ROW SELECTED but the table actually has data

In my production, There is a table named ABC under X schema. I have granted SELECT privilege on ABC table to another user named Z. When I execute the query SELECT COUNT(*) FROM X.ABC; as user Z it ...
0
votes
3answers
53 views

Select only records that have different values for a particular column

In my table there are some records that have different name values for the same account number and I want to extract only the records that have different values in the name field, but that share the ...
1
vote
0answers
8 views

Relation Algebra: Selection of Cartesian Product

I am learning Relational Algebra basics for sql. I came across an example where the selection of cartesian product of two relations (R1 x R2) has been taken and I realize that it is same as selection(...
0
votes
2answers
100 views

why optimizer in Oracle database does not use index?

when I execute following queries see completely different result where is problem? here I execute a simple select query which takes a few seconds to complete: SELECT * FROM PRODUCTION....
1
vote
1answer
16 views

Finding average of multiple delta times

I'm looking to find the average interval between successive rows across the whole query - delta-previous in below example: SELECT *, "RecognitionTimestamp" - lag("RecognitionTimestamp") OVER(ORDER ...
2
votes
6answers
90 views

SELECT all rows with sequential id after a specific id

Is it possible to query all rows that their ids are sequential after a specific id? (id is an AUTO_INCREMENT column.) For example, suppose my specific id is 5. Then I want all rows with these ids: ...
0
votes
1answer
14 views

select query on postgis not working for specific fields [closed]

So I have what seems to be a really weird problem. I have imported a table from QGIS into a postgresql + postgis database. I simply want to select a few columns from that, but I can't. whats funny ...
1
vote
0answers
34 views

InfluxDB - How to get start timestamp of alternating series

I have these data series in an influx database, alternating between 0 and 1. 2018-10-02T07:12:00Z 0 2018-10-02T07:15:00Z 0 2018-10-02T07:18:00Z 0 2018-10-02T07:21:00Z 0 2018-10-02T07:24:00Z 0 2018-10-...
0
votes
1answer
49 views

MySQL: Trying to “normalize” data using MySQL to help

I inherited a spreadsheet with 1600+ records, which I simply inserted into a single table (mapping) in MySQL. I'd like to use the power of MySQL to help me do some "normalization", à la the MySQL ...
2
votes
0answers
24 views

How to select all results tied for first position

My current output is a list of caretakers and how many budgies they take care of. I get it via the following SELECT statement: SELECT caretakers.name, COUNT(species.name) FROM caretakers JOIN ...
0
votes
1answer
25 views

What is the best solution to prevent picking the same value (by multiple requests)?

Situation: there is a table "Tours" which contains a lot of generated records with different properties (Color, Priority, PickedUp). The goal is to allow external application (over REST API) to pick ...
0
votes
1answer
22 views

Return proper column based on other column's values

Consider an EAV table with separate columns for each datatype: CREATE TABLE eav_values ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, entity_id INT NOT NULL, name VARCHAR(127) NOT NULL, ...
0
votes
2answers
36 views

How to SELECT multi-columns from a column?

I have a table with the structure book_id int(11), section_id int(11), note_id int(11), item_number int(11), text varchar(255), UNIQUE(book_id,section_id,note_id,item_number) item_number can be 1 or ...
1
vote
1answer
29 views

Query to partially summarize data in a table using SQL

I'm learning how to handle databases, so this is a trivial question, and quite likely has been answered already. I'm just not familiar to the lingo and have no idea how to search for it (although I ...
0
votes
2answers
127 views

MySQL 5.1 - long running select locking the table and not allowing inserts

Platform - MySQL 5.1, MyISAM engine We reached max on int (id, auto increment) in our Prod system. Changed the type to BigInt. Even since this change was made, long running selects are locking the ...
1
vote
0answers
55 views

Why does the Select statement stalls when executed directly in sequence?

When executing the following in workbench or in code, the Drop table/Create Table works ok. The Select statement stalls when executed in one go. If the table is MyIsam, it works ok. If executed [...
0
votes
1answer
302 views

insert with multiple row return through select [closed]

I want to insert multiple rows return from select statement with different uid, lets select statement return (1,2,4,5); INSERT INTO `notifications`( `Text`, `uid`, `read_status`) VALUES ("abc",(...
1
vote
2answers
128 views

Update selected data from same table column as currency

I am trying to update selected data from a table column and format this data as currency. My table column holds strings that have both mixed whole numbers and already formatted data. This was due to ...
0
votes
1answer
414 views

mysql update based on select result, How combine?

Here are two SQL statements. One is an select statement and the other is a update statement. I want to combine them. Select SELECT * FROM test WHERE `id`='1' Update UPDATE test SET `select_count`=...
1
vote
0answers
19 views

MS Access 2016 M:N relationships return multiple columns instead of multiple rows from a JOIN

Let's assume a data model like this: Books could have multiple authors as well as authors could have written multiple books. If a book and its authors are selected by the following statement (this ...
1
vote
3answers
48 views

Show rows with non-unique value in one field

I'm familiar with how to aggregate rows as shown in this answer: Show only duplicate values I'm also familiar with how to filter the aggregated results using a HAVING clause. What I can't seem to ...
0
votes
1answer
98 views

SSRS - select where parameter and fixed value

So there is a lot of stuff about using SSRS parameters to select multiple values but nothing about using both a parameter and a fixed value using the in select statement. So what I'm trying to do is ...
0
votes
1answer
66 views

JOIN and GROUP BY with additional columns

If I run the following query on my database I get the results pasted below: SELECT t.id as ID, j.text as Text, l.location as Location, FROM [text] t WITH (nolock) INNER JOIN Text_Location tl WITH (...