Questions tagged [select]
Select is a common keyword used to query data. 'select()' is also a programming function for triggering code based on file handle or other system activity. Do not use this tag for questions related to: HTML <select> tag (use [html-select]); language integrated query such as LINQ or similar, etc.
38,811
questions
1750
votes
22
answers
4.0m
views
Selecting multiple columns in a Pandas dataframe
How do I select columns a and b from df, and save them into a new dataframe df1?
index a b c
1 2 3 4
2 3 4 5
Unsuccessful attempt:
df1 = df['a':'b']
df1 = df.ix[:, 'a':'b']
1210
votes
29
answers
2.6m
views
SQL Update from One Table to Another Based on a ID Match
I have a database with account numbers and card numbers. I match these to a file to update any card numbers to the account number so that I am only working with account numbers.
I created a view ...
1011
votes
15
answers
4.4m
views
SQL SELECT WHERE field contains words
I need a select which would return results like this:
SELECT * FROM MyTable WHERE Column1 CONTAINS 'word1 word2 word3'
And I need all results, i.e. this includes strings with 'word2 word3 word1' or '...
989
votes
17
answers
2.9m
views
jQuery get value of select onChange
I was under the impression that I could get the value of a select input by doing this $(this).val(); and applying the onchange parameter to the select field.
It would appear it only works if I ...
686
votes
12
answers
1.5m
views
MySQL - UPDATE query based on SELECT Query
I need to check (from the same table) if there is an association between two events based on date-time.
One set of data will contain the ending date-time of certain events and the other set of data ...
633
votes
29
answers
913k
views
How to make the first option of <select> selected with jQuery
How do I make the first option of selected with jQuery?
<select id="target">
<option value="1">...</option>
<option value="2">...</option>
</select>
602
votes
25
answers
806k
views
How to get a list of column names on Sqlite3 database?
I want to migrate my iPhone app to a new database version. Since I don't have some version saved, I need to check if certain column names exist.
This Stackoverflow entry suggests doing the select
...
572
votes
6
answers
851k
views
Create a temporary table in a SELECT statement without a separate CREATE TABLE
Is it possible to create a temporary (session only) table from a select statement without using a create table statement and specifying each column type? I know derived tables are capable of this, but ...
569
votes
14
answers
824k
views
How to select all columns except one in pandas?
I have a dataframe that look like this:
a b c d
0 0.418762 0.042369 0.869203 0.972314
1 0.991058 0.510228 0.594784 0.534366
2 0.407472 0.259811 0.396664 0....
502
votes
5
answers
675k
views
Select objects based on value of variable in object using jq
I have the following json file:
{
"FOO": {
"name": "Donald",
"location": "Stockholm"
},
"BAR": {
"...
499
votes
20
answers
770k
views
Select columns from result set of stored procedure
I have a stored procedure that returns 80 columns, and 300 rows. I want to write a select that gets 2 of those columns. Something like
SELECT col1, col2 FROM EXEC MyStoredProc 'param1', 'param2'
...
489
votes
19
answers
1.1m
views
MySQL: Select DISTINCT / UNIQUE, but return all columns?
SELECT DISTINCT field1, field2, field3, ......
FROM table;
I am trying to accomplish the following SQL statement, but I want it to return all columns.
Is this possible?
Something like this:
SELECT ...
478
votes
13
answers
410k
views
SQL join: selecting the last records in a one-to-many relationship
Suppose I have a table of customers and a table of purchases. Each purchase belongs to one customer. I want to get a list of all customers along with their last purchase in one SELECT statement. What ...
472
votes
4
answers
572k
views
jq: how to filter an array of objects based on values in an inner array?
Given this input:
[
{
"Id": "cb94e7a42732b598ad18a8f27454a886c1aa8bbba6167646d8f064cd86191e2b",
"Names": [
"condescending_jones",
"...
466
votes
6
answers
924k
views
SQL query return data from multiple tables
I would like to know the following:
how to get data from multiple tables in my database?
what types of methods are there to do this?
what are joins and unions and how are they different from one ...
464
votes
34
answers
492k
views
Select all columns except one in MySQL?
I'm trying to use a select statement to get all of the columns from a certain MySQL table except one. Is there a simple way to do this?
EDIT: There are 53 columns in this table (NOT MY DESIGN)
404
votes
10
answers
272k
views
Why does the jquery change event not trigger when I set the value of a select using val()?
The logic in the change() event handler is not being run when the value is set by val(), but it does run when user selects a value with their mouse. Why is this?
<select id="single">
<...
403
votes
6
answers
1.6m
views
Convert INT to VARCHAR SQL
I am using Sybase and I am doing a select which returns me a column called "iftype", but its type is int and I need to convert into varchar. When I try to do the select without the convert function I ...
396
votes
4
answers
396k
views
MySQL Select all columns from one table and some from another table
How do you select all the columns from one table and just some columns from another table using JOIN? In MySQL.
384
votes
8
answers
290k
views
How to get Top 5 records in SqLite?
I have tried this which did not work.
select top 5 * from [Table_Name]
380
votes
12
answers
318k
views
How to best display in Terminal a MySQL SELECT returning too many fields?
I'm using PuTTY to run:
mysql> SELECT * FROM sometable;
sometable has many fields and this results in many columns trying to be displayed in the terminal. The fields wrap onto the next line so it ...
360
votes
7
answers
367k
views
MySQL - How to select data by string length
SELECT * FROM table ORDER BY string_length(column);
Is there a MySQL function to do this (of course instead of string_length)?
342
votes
16
answers
712k
views
How can I select from list of values in SQL Server
I have very simple problem that I can't solve. I need to do something like this:
select distinct * from (1, 1, 1, 2, 5, 1, 6).
Anybody can help??
Edit
The data comes as a text file from one of ...
321
votes
12
answers
799k
views
MySQL SELECT only not null values
Is it possible to do a select statement that takes only NOT NULL values?
Right now I am using this:
SELECT * FROM table
And then I have to filter out the null values with a php loop.
Is there a ...
315
votes
13
answers
317k
views
Can I apply the required attribute to <select> fields in HTML?
How can I check if a user has selected something from a <select> field in HTML?
I see <select> doesn't support the new required attribute... do I have to use JavaScript then? Or is there ...
296
votes
18
answers
404k
views
jQuery: Best practice to populate drop down?
The example I see posted all of the time seems like it's suboptimal, because it involves concatenating strings, which seems so not jQuery. It usually looks like this:
$.getJSON("/Admin/GetFolderList/"...
295
votes
8
answers
312k
views
How to get values from IGrouping
I have a question about IGrouping and the Select() method.
Let's say I've got an IEnumerable<IGrouping<int, smth>> in this way:
var groups = list.GroupBy(x => x.ID);
where list is a ...
291
votes
14
answers
375k
views
MySQL: is a SELECT statement case sensitive?
Is a MySQL SELECT query case sensitive or case insensitive by default? And if not, what query would I have to send so that I can do something like the following?
SELECT * FROM `table` WHERE `Value` = &...
279
votes
4
answers
159k
views
COUNT(*) vs. COUNT(1) vs. COUNT(pk): which is better? [duplicate]
I often find these three variants:
SELECT COUNT(*) FROM Foo;
SELECT COUNT(1) FROM Foo;
SELECT COUNT(PrimaryKey) FROM Foo;
As far as I can see, they all do the same thing, and I find myself using the ...
277
votes
10
answers
675k
views
SQL WHERE ID IN (id1, id2, ..., idn)
I need to write a query to retrieve a big list of ids.
We do support many backends (MySQL, Firebird, SQLServer, Oracle, PostgreSQL ...) so I need to write a standard SQL.
The size of the id set could ...
275
votes
5
answers
961k
views
JOIN two SELECT statement results
Is it possible to join the results of 2 sql SELECT statements in one statement?
I have a database of tasks where each record is a separate task, with deadlines (and a PALT, which is just an INT of ...
252
votes
22
answers
1.1m
views
Select arrow style change
I'm trying to replace the arrow of a select with a picture of my own. I'm including the select in a div with the same size, I set the background of the select as transparent and I'm including a ...
247
votes
17
answers
377k
views
Best way to unselect a <select> in jQuery?
<select size="2">
<option selected="selected">Input your option</option>
<option>Input your option</option>
</select>
What is the best way, using jQuery, to ...
246
votes
17
answers
249k
views
How to select multiple rows filled with constants?
Selecting constants without referring to a table is perfectly legal in an SQL statement:
SELECT 1, 2, 3
The result set that the latter returns is a single row containing the values. I was wondering ...
235
votes
10
answers
1.0m
views
Best way to do nested case statement logic in SQL Server
I'm writing an SQL Query, where a few of the columns returned need to be calculated depending on quite a lot of conditions.
I'm currently using nested case statements, but its getting messy. Is there ...
231
votes
7
answers
456k
views
Select records from NOW() -1 Day
Is there a way in a MySQL statement to order records (through a date stamp) by >= NOW() -1 so all records from the day before today to the future are selected?
218
votes
49
answers
114k
views
Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc
I've heard that SELECT * is generally bad practice to use when writing SQL commands because it is more efficient to SELECT columns you specifically need.
If I need to SELECT every column in a table, ...
217
votes
7
answers
184k
views
Does a break statement break from a switch/select?
I know that switch/select statements break automatically after every case. I am wondering, in the following code:
for {
switch sometest() {
case 0:
dosomething()
case 1:
...
215
votes
16
answers
657k
views
Fastest way to determine if record exists
As the title suggests... I'm trying to figure out the fastest way with the least overhead to determine if a record exists in a table or not.
Sample query:
SELECT COUNT(*) FROM products WHERE ...
213
votes
9
answers
490k
views
Return Boolean Value on SQL Select Statement
How to return a boolean value on SQL Select Statement?
I tried this code:
SELECT CAST(1 AS BIT) AS Expr1
FROM [User]
WHERE (UserID = 20070022)
And it only returns TRUE if the UserID exists on the ...
205
votes
4
answers
165k
views
Postgres: Distinct but only for one column
I have a table on pgsql with names (having more than 1 mio. rows), but I have also many duplicates. I select 3 fields: id, name, metadata.
I want to select them randomly with ORDER BY RANDOM() and ...
203
votes
5
answers
207k
views
Select 50 items from list at random
I have a function which reads a list of items from a file. How can I select only 50 items from the list randomly to write to another file?
def randomizer(input, output='random.txt'):
query = open(...
203
votes
3
answers
122k
views
What are the differences between poll and select?
I am referring to the POSIX standard select and poll system C API calls.
202
votes
9
answers
417k
views
Get index of selected option with jQuery
I'm a little bit confused about how to get an index of a selected option from a HTML <select> item.
On this page there are two methods described. However, both are always returning -1. Here is ...
199
votes
6
answers
374k
views
How can I use optional parameters in a T-SQL stored procedure?
I am creating a stored procedure to do a search through a table. I have many different search fields, all of which are optional. Is there a way to create a stored procedure that will handle this? ...
190
votes
18
answers
729k
views
How to select distinct rows in a datatable and store into an array
I have a dataset objds. objds contains a table named Table1. Table1 contains column named ProcessName. This ProcessName contains repeated names.So i want to select only distinct names.Is this possible....
177
votes
6
answers
531k
views
Select rows of a matrix that meet a condition
In R with a matrix:
one two three four
[1,] 1 6 11 16
[2,] 2 7 12 17
[3,] 3 8 11 18
[4,] 4 9 11 19
[5,] 5 10 15 20
I want to extract the ...
176
votes
5
answers
474k
views
MySQL SELECT WHERE datetime matches day (and not necessarily time)
I have a table which contains a datetime column. I wish to return all records of a given day regardless of the time. Or in other words, if my table only contained the following 4 records, then only ...
171
votes
3
answers
324k
views
MySQL Select Query - Get only first 10 characters of a value
Ok, so here is the issue.
I have a table with some columns and 'subject' is one of the columns.
I need to get the first 10 letters from the 'subject' field no matter the 'subject' field contains a ...
165
votes
7
answers
345k
views
MySQL Query - Records between Today and Last 30 Days
I want to return all records that were added to the database within the last 30 days. I need to convert the date to mm/dd/yy because of display purposes.
create_date between DATE_FORMAT(curdate(),'...