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

2
votes
2answers
166 views

How do I set the isolation level for SELECT statement?

Using PostgreSQL 9.5 I would like to make sure that when I run a SELECT statement I get consistent results, i.e. if the table is modified while the SELECT is running, I want to get the state that was ...
1
vote
2answers
20 views

How to select distinct record?

I have a table, as follows: ID | Name | MyID 1 | Alan | 2 2 | Alan | 2 3 | John | 3 I want to select the records as follows: If two records have the duplicate ...
4
votes
2answers
58 views

MySQL - Order by closest value on multiple columns

I have a table for a game lobby. In this lobby a user gets put in their connection and their level. In my SQL statement I am getting all the users in the lobby which are between +5/-5 of the user's ...
1
vote
1answer
55 views

Vertica performance on select from view with union

We have a huge number of rows(tens of millions), and for each table we have an associated view that is a select with UNION ALL between that table and several others. Now, we are doing a select from ...
3
votes
3answers
76 views

SELECT + INSERT or INSERT alone

I have an application where several devices send data every second to my server. On the database I have a table with the devices and another table with the data sent every second. The first time a ...
3
votes
2answers
25 views

Howto (async?) preview intermediate resultset

Is it possible to retrieve parts of the resultset from SQL Server queries in advance? For instance if I run a query that will return 20,000 rows, is it possible to throw the results in packages of ...
2
votes
1answer
57 views

How to get number of active users with one SQL-Query?

I am running a site similar to craigslist where users can create classifieds and write/reply messages. In order to get an idea of activity I would like to get the amount of active users per month. ...
1
vote
0answers
36 views

Fetch items where related rows has different values

I have table in MySQL called attributes, and other table, attribute_values, one attribute can have multiple values, values identified by context attribute and has value_c attribute wich contain value. ...
1
vote
1answer
27 views

Cities and States (a few data): single table or splitted?

I am designing a DB schema and I need to store cities and states. I expect only a few rows, let's say, 20 cities. Example: id | city | state 1 | Rio de Janeiro | RJ 2 | Niteroi ...
1
vote
1answer
40 views

How to select data from differents servers with a single query?

I have a challenge! I need select from 4 different tables from 4 different servers. Example: Select * from server1.tableS1.sys.view Select * from server2.tableS2.sys.view Select * from ...
2
votes
2answers
98 views

Select random rows up to a limit

SELECT * FROM my_players WHERE player_type = 'IF' ORDER BY cardweight / rand() DESC limit 3 That is my current query, What I am trying to do is select random rows for which I have the * in my query, ...
1
vote
1answer
23 views

SELECT with equal chance between same IDs - MySQL

How can I SELECT data with equal chances for same IDs in MySQL (for php). For example, assume below data structure: id value 1 alfa 1 beta 1 gamma 2 hello 2 bye 3 sky I want ...
0
votes
1answer
18 views

How can I access certain information from YQL?

I notice the YQL commands such as select * from yahoo.finance.quote where symbol in ("YHOO") return all the data for that certain stock. I was wondering is it possible to access data from YQL ...
3
votes
2answers
38 views

Get rows with minimum value

I have tables company: company_id | - - - - - - - - - - - - - - 1 | 2 | employee: employee_id | - - - - - - - - - - - - 1 ...
2
votes
1answer
37 views

Join two SELECT results with the same post_id value

I need to do a query to the MySQL database of my site built in WordPress / WooCommerce. The 'wp_posts' table keeps products, articles and more. Every row in 'wp_posts' has a 'post_id' to connect ...
4
votes
2answers
72 views

Indexed but still slow during query

I have a table that stores REST requests and responses: CREATE TABLE ws_call_logs ( id BIGINT NOT NULL, ws_method_id BIGINT NOT NULL, device_id ...
5
votes
2answers
66 views

Same record shows up multiple times in ordered paginated query

Some records show up on multiple result "pages" with the following query: SELECT `description`, `wallpaper` FROM `bbr_bar` WHERE `country_id` = '2510769' ORDER BY `online` DESC ...
3
votes
1answer
64 views

SQLite Like clause match whole word only

I have a SQLite database with a table named: minecraft +----+----------------------+ | id | name | +----+----------------------+ | 1 | Pocket Mine MP | | 2 | Open Computers ...
0
votes
0answers
31 views

Display Complete Month With or Without TIMESTAMP field

Please edit the title if you have a better, I didn't find other words to describe this. Environment Fields: |id|time|text| Situation I have to make a report with the total of records per day, ...
0
votes
1answer
47 views

MySQL: Select two values of two columns and compared their values exchanging them each other

I need to find a way to select one random row where the subscriber is not also leader (in the same or any other row). Something like this: (just to have an idea) SELECT `leader`,`subscriber` FROM ...
2
votes
2answers
56 views

CTE To Use Alternate Select When Select Returns No Rows

I have created a involved CTE, no recursion, with multiple selects being done as it processes the business logic of the requirement. But I have been advised that the logic needed for the scenario ...
2
votes
2answers
47 views

Search multiple values in multiple columns

I have a table results with this fields: id results_id number_one (int) number_two (int) number_three (int) number_four (int) number_five (int) Each number_* column can contain a number from 01 to ...
1
vote
1answer
41 views

Unknown column 'actions_in_group' in 'field list'

I keep getting: Unknown column 'actions_in_group' in 'field list' Here's the SQLFiddle: http://sqlfiddle.com/#!9/4ddf0/19 SELECT *, SUM(actions_in_group) AS total_rows_in_group, ...
0
votes
2answers
36 views

Combining two similar queries into one (PostgreSQL)

I have 2 queries like this: SELECT c.id FROM component c, base_vee bv WHERE c.id IN (SELECT component_id FROM registry_row WHERE registry_id = 199) AND c.id = ...
0
votes
1answer
90 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
54 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
22 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
22 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
75 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
56 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
57 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
63 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
32 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
35 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
34 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
66 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
34 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
40 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
62 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 ...
1
vote
0answers
65 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
53 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
67 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
540 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 ...
1
vote
1answer
30 views

putting together contents of XML column - from all rows of a table - how to get it done without a “while”?

I have a table called sizeguide with the definition you can see below. I am interested in the SizeGuideXML column, which is type XML. I had a mission the objective was, for each SizeGuideDesc, get ...
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
67 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 ...