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.

learn more… | top users | synonyms

0
votes
1answer
191 views

Simple select query taking too long

I have been having a hard time with this query, I have a webpage which is supposed to run this query a dozen of times, and with an execution time up to 40 - 50 seconds per query, you can see how this ...
0
votes
1answer
144 views

Efficient way to get last 10 rows of each group in SQLite, can CTE help?

Consider there is a table of job runs history with the following schema: job_runs ( run_id integer not null, -- identifier of the run job_id integer not null, -- identifier of the job ...
0
votes
0answers
12 views

Selecting entries which have all relations [duplicate]

I have 3 tables: A, B, C. Tables A and C have fields: ID, Name and they are related many-to-many through B table with fields A_ID, C_ID. How can I select the entries from A which have relations to ...
0
votes
0answers
29 views

Need help with Oracle Query for totaling fields with separate clauses, any feedback highly appreciated!

I am stuck on an issue that has been causing my mind to ramble for the last couple of days. DETAILS ABOUT REPORT This report is to identify the following details based off of the CUSTOMER_ID new ...
0
votes
0answers
26 views

How can I combine join and random choice from one table but 2 conditions?

I want to choose 200 entries randomly from a table However, I have two conditions the first 100 should be white and the other black. How can I join them? One possibility to do is to run following ...
-1
votes
1answer
25 views

Setting An Order For Specific Fields Using SELECT and ORDER BY

So I'm writing a query to show the hire_date, job_id and last name where the last name= 'Matos' and 'Taylor and the hire_date is in ascending order. When executing this code: SELECT last_name, ...
0
votes
2answers
84 views

Which row is selected by DISTINCT?

I have a table with products with names in different languages: product-id | lang-no | name Now I want to generate product lists with names in each language. Unfortunately I don't have all names in ...
-4
votes
1answer
59 views

SELECT TOP (or MAX) for each Specific value [closed]

Lets say i have this table ____________________________ | EmployeeID | Sales | |------------|-------------| | 1 | 300 | | 1 | 350 | | 2 | 400 ...
0
votes
0answers
67 views

MySQL Match … Against query very slow

I work on a website running on Propel ORM and I have this query: if(isset($args["QueryText"]) && $args["QueryText"] != "") { $query = $query ->withColumn("(MATCH (Request.Subject, ...
-1
votes
3answers
64 views

Using the name of an “AS” column in the WHERE clause

I have the following query in mysql: SELECT voter_id, first, middle, last, title, party, phone, ward, households.hh_id, households.hh_long, voters.1311 + voters.1111 + voters.0911 + voters.0909 + ...
0
votes
1answer
35 views

Update rows in a table with an index column starting from 0 with consecutive numbers

I have a few tables in a Oracle db with some "rule": The INDEX_COLUMN must start from 0 and must be consecutive numbers and the column NRCRT must start from 1 and also consecutive numbers. I've made a ...
1
vote
0answers
45 views

Matching same unknown characters in two columns

So here is the situation. I have a database with values in columns that look something like this field_0_data1, field_0_data2, field_1_data1, field_1_data2 Is it possible to only select the columns ...
1
vote
0answers
43 views

Find the last record of group of overlapped records

I have a little dilemma with filtering out result. The result and what I want to achieve is not very trivial and I didn't find an answer anywhere after extensive search. So here is my problem: I ...
0
votes
1answer
78 views

How to find the price based on the given range

Here i need to find the price of the qty based on which price range the qty lies. In the first date(2015/01/01) 5 quantities have been sold and we made entries from (1 to 5) ,On second day for 10 ...
0
votes
1answer
40 views

Select Unique Fields with Max Values in Each?

I have a table with names, numbers, and timestamps on the data. I want to know how to select a unique instance of each name based on how recent the timestamp is. Addy (text), NW (number), UDate ...
0
votes
2answers
46 views

Granting Select access to all tables within a specific Database in MS SQL

I have a server that has multiple databases that are contained within that same server/project. I am using MS SQL Server 2012. I have a special role set up with 3 users that are apart of that role. I ...
0
votes
0answers
28 views

a student with multi race code in a column transpose to a row [duplicate]

studentid racecd --------- ------ 1780 400 1780 500 1780 700 change to studentid race1 race2 race3 --------- ----- ----- ----- 1780 400 500 ...
0
votes
2answers
48 views

sql problem with multiple linked tables

I have an Oracle db and the following tables: raportor: id id_pct_lucru 58382 327342 ses_rap id an status 1 2012 I 21 2013 I 41 2014 D ch_trat id fk_id_raportor ...
0
votes
0answers
68 views

rows to columns using SQL , merge queries

I would like to merge these two queries: SELECT um.user_id, um.meta_value, u.display_name, u.user_email, u.user_url, t.name FROM wp_usermeta um INNER JOIN wp_users u on u.id = um.user_id INNER JOIN ...
0
votes
0answers
93 views

Fetching from parent/child table pairs

Let there are two tables: "parent" and "child" related by 1:n relation (to every "parent" row there correspond any number of "child" rows). Suppose we need to fetch a subset of parent table with all ...
0
votes
1answer
54 views

Prioritizing values in select statement in ORACLE

Due to the JOIN for the communication method (Phone, email etc) we get alot of duplicates because a company can have multiple communication methods (CICM.CLIENT_VALUE). My question is... Is there a ...
1
vote
2answers
74 views

How to get the value of column that the same for few rows by selecting values from other columns?

Since I am not a MySQL expert, I am having trouble determining how to ask a search engine for advice on this topic. I have the following table: +------------+--------------+-------------------+ | ...
0
votes
3answers
1k views

Lock mysql table to prevent select and insert at the same time

I know this question has been asked earlier and I have also read the documentation. But I guess I'm stupid not understand. I have a code that inserts a row and the row should be unique in several ...
0
votes
0answers
36 views

MySQL - SELECT Columns from results of another Query [duplicate]

I'm trying to use a dynamic range of columns fetched from another query, specifically I want the results of this query: SELECT COLUMN_NAME as DYNAMIC_COLUMN FROM information_schema.columns WHERE ...
0
votes
1answer
82 views

Select not repeated results from same tables in different databases

I have 3 tables in 3 different databases which are exactly the same. I'm trying to sync from this 3 databases to a master database as shown in the picture below: Right now I am running the same ...
0
votes
1answer
191 views

Count distinct values of a column and insert them to another table

So, I have a database for logs and statistics. But, the amount of data sent is too high, so I was thinking of grouping the data into another table. So the structure of the original Database is: ID ...
0
votes
2answers
146 views

Error on simple Select statement: Subquery returned more than 1 value

When I query a table select * from tableName it returns error msg Msg 512, Level 16, State 1, Line 2 Subquery returned more than 1 value. This is not permitted when the subquery follows =, ...
-2
votes
1answer
27 views

Selecting different variables depending on another variable [closed]

I must make a new table with filling up fields depending on a variable. If type = holder, then I should take the enterprise field, if type = requester, I should take the name. How do i write this in ...
2
votes
2answers
85 views

Query to know who paid more than 10k

I have a table with payment informations, like this: ID COSTUMER_ID DATEPAID AMOUNT 1 1 2012-01-01 50 2 1 2012-02-01 100 3 1 2012-03-01 70 4 2 ...
0
votes
2answers
60 views

select where column with a %

How can I select all records with a % in? I think this code doesn't work. SELECT column1, column2 FROM table WHERE column1 LIKE '%%%' first and last % for zero, one or more chars second % for the ...
0
votes
1answer
325 views

selecting same column twice for different value

I have a table like this; event_id pair versus score 1 1 11 100 1 1 12 0 ... 1 11 1 0 1 12 1 50 Now I want to ...
0
votes
1answer
157 views

Select last record from my table [closed]

I am new to SQL and PHP. I'm having a problem with selecting the last record from my table. I run the following query: SELECT * FROM 2521118 ORDER BY id DESC LIMIT 1 My table name is 2521118 and ...
0
votes
2answers
238 views

Remove duplicates from multiple joins

I'm using WordPress $wpdb->get_results for this query (it is simplified for question purposes): SELECT customer.id, customer.name, address.address appt.appointment_date, pay.date FROM customers ...
6
votes
2answers
496 views

MySQL: Show list of tables with paging in Terminal

I am using MySQL Ver 14.14 Distrib 5.5.44 for debian-linux-gnu. How can I show my tables page wise in a terminal?
0
votes
3answers
29 views

I want a select to give me id's that are not in a consecutively order

I have an Oracle db with a table like this: +----+-------+ | ID | INDEX | +----+-------+ | 1 | 0 | | 1 | 1 | | 2 | 4 | | 2 | 5 | | 2 | 6 | | 3 | 0 | | 3 | 1 | | 3 ...
2
votes
3answers
82 views

Generate a list from columns that do not contain a zero for each row

I have a table TAB1 in an Oracle database: +----+----+----+----+----+----+ | ID | C1 | C2 | C3 | C4 | C5 | +----+----+----+----+----+----+ | 1 | 1 | 0 | 3 | 0 | 5 | | 2 | 11 | 22 | 0 | 44 | ...
5
votes
1answer
266 views

Exactly what error is returned by PostgreSQL `FOR UPDATE NOWAIT` when a selected row cannot be locked immediately?

The PostgreSQL 9.4 documentation states that adding the NOWAIT option to a SELECT FOR UPDATE means an error is generated when a row cannot be locked: To prevent the operation from waiting for ...
3
votes
1answer
42 views

Extra “count” row with total of 0

Consider the following: db=> SELECT ga, count(ga) FROM gb GROUP BY ga ORDER BY ga ; which gives the following output: ga | count ---+------ ? | 200 A | 100 B | 50 | 0 (4 rows) ...
2
votes
4answers
380 views

WHERE NAME LIKE ( A SET OF NAMES )

I would like to drop all the jobs related to a set of specific databases. So I have added all the names into a table variable and I was trying to generate the scripts to drop the jobs. how can I ...
1
vote
2answers
330 views

Select Between Date Range Mysql

I want to select records between 2 dates: select * from orders where orders.created <= '2015-07-31'; select * from orders where orders.created >= '2015-07-01' and orders.created <= ...
1
vote
1answer
55 views

Recommended Database(s) for Selecting Random Rows

I'm familiar with selecting random rows from a table in PostgreSQL. It's really slow. I've looked into some other databases and they all seem to be bad at it. Mostly because it's not a normal use case ...
1
vote
0answers
41 views

Row locks on selects

select t.*, row_number() over ( partition by t.Entity_Identifier order by t.Message_Sequence ) as seqnum from Process_Activity t (ROWLOCK) where t.Process_Id = Is it possible for ...
4
votes
1answer
143 views

Fast alternative for “NOT IN”

I have a table A that got a field called id that is the primary key of this table. I also have a table called B which also have a field called id as primary key. Now I want to get all rows from ...
4
votes
2answers
2k views

Select only those records that have different/multiple values for a particular column

Below is an example of my membership table. There some records having multiple values in the email field. I only want to select those records that have multiple email values: Member table ID ...
0
votes
2answers
73 views

MYSQL Select, where rows exists

I have a Mysql Database and tables with the structure: Table 'photos' - ID, Name Table 'photos_tags' - Key, Photo_ID, Tag My goal is to select all photos, which has one tag (it's not a problem) ...
0
votes
3answers
171 views

If in mysql I have string `xxx yyy` - how can I SELECT this if user input `xxxyyy`?

My online-shop in PHP (OpenCart). On site we have product-search. For example product have name iSport 220, and if user search input string is iSport220 we must show this product. And vice versa. ...
2
votes
2answers
66 views

Cannot build correct SELECT in MySql

Please help me to create a correct MySql query, which I failed to do. I have 2 tables in our DB: CREATE TABLE IF NOT EXISTS `user_audit` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, ...
0
votes
2answers
61 views

PostgreSQL, merge join results

I have 2 tables with common columns and would like to know if it's possible to request this 2 tables by merging the results. Table "job" : parent_id, target_id, start_date, end_date, jobposition_id ...
5
votes
1answer
78 views

How to Choose Between VALUES and SELECT for INSERT?

This answer raised the question for me how to choose between VALUES and SELECT in such a function . Using PostgreSQL 9.4.3 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit: ...
6
votes
2answers
727 views

Optimizing WHERE condition for TIMESTAMP field in MySQL SELECT statement

I am working on a schema for an analytics system which tracks usage times, and there is a need to see total usage time in a certain date range. To give a simple example, this type of query would be ...