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.
1
vote
1answer
265 views
Merge 2 tables and fetch data one by one
I have two tables: product & offers.
products has (prod_id, category_id, prod_name, brand, price, status)
offers has (offer_id, prod_id, offer_type, discount_amt, validity)
I want to display ...
1
vote
1answer
561 views
How do I perform a UNION query on a dynamic list of tables?
My database has an unknown amount of tables, named with the same prefix followed by a random string: _ct_<random_string>.
Each of these tables has the same data structure.
I also have another ...
1
vote
0answers
86 views
Get all comment.message, status.message, users.* and profiles.* where users.user_id exists in friend.friend_id or friend.user_id
I need some help building this query because it's a bit complicated at least for me. I need to get all comment.message, status.message, users.* and profiles.* where users.user_id exists in ...
0
votes
3answers
347 views
Can a RDBMS connect to a remote server, execute a select query and copy them into a local table just with SQL commands?
I'm sorry it may sound stupid but I've been wondering about how multiple databases are automated before the virtualization era. Can a DB Adminsitrator make a stored procedure to get data from a remote ...
0
votes
1answer
141 views
Error “column does not exist” in a SELECT with JOIN and GROUP BY query
I'm using PostgreSQL 9.1 with a Ruby on Rails application.
I'm trying to list the last version of each "charge" (in my history table : hist_version_charges) belonging to the same project id ...
0
votes
2answers
120 views
MySQL: SELECT the n-th item from an ordered result
SELECTing the top n elements from a table is easy:
SELECT id FROM pixels WHERE pixel_id='some_pixel_id' ORDER BY id DESC LIMIT 1000;
Finding the n-th element with a subquery is quite ...
0
votes
1answer
70 views
Can you search using an index while indexes are being updated in oracle11g?
I am using oracle 11g. I noticed some performance problems that causes hanging on some search operations.
Can I still search based on an index while that index is being updated in the database?
0
votes
2answers
193 views
How to mix pairs of rows without JOIN (in a temporary table)?
I have a TEMPORARY table containing pairs of key/value as
id col1 col2 type pair
1 key1 key2 key 1
2 value1 value2 value 1
3 key3 ...
0
votes
1answer
104 views
Retrieving a fixed range of rows from Postgresql
I have a query:
select qid,ansid,ans from table1 where askerid='something'
This query can retrieve many rows. But I want to display only 50 rows at a time and then if the user clicks on more, the ...
0
votes
1answer
159 views
Select fields from multiple tables
I want to make a query a little complicated, and I'm not able to do it alone.
I have the following tables:
Table color:
id_uo P
id_cor PF
id_area F
text_cor
Table area:
id_area P
...
0
votes
2answers
156 views
MySQL: Join one Row in a table with two Rows in other table
In my MYSQL Database COMPANY. I have two tables, like below in my diagram (arrow shows relations):
`users` `user_login`
+--------------+ ...
0
votes
2answers
74 views
Need a way to query a table, and JOIN it with the TOP 1 related record from an other table
As a follow up to this question, I'm wondering if there is a better and/or more efficient way to gather the data in question.
As stated, this query does return me 95% of the data I need --
SELECT ...
0
votes
2answers
129 views
MySQL Reusing calculation in SELECT clause in a VIEW
I have an SQL query that has a simple date difference between NOW() and the creation date (is in the table). I need to reuse this again within the SELECT clause in a VIEW. Is this possible at all?
...
0
votes
2answers
80 views
SQL and Multiple Indexes
Consider the following table:
i | a | b | c
--------------
0 | 1 | 2 | 3
1 | 4 | 5 | 6
2 | 7 | 8 | 9
3 | x | y | z
The table, in the end, will have several thousand rows, and even more columns then ...
0
votes
3answers
145 views
How can I select data and the total to cursors?
I have a table like this:
ID | Name
------------
1 | AA
2 | AA
3 | AA
4 | BB
I want to select all rows where Name like 'AA' in a cursor and get the count from this result in another ...
0
votes
2answers
83 views
“For each group of results fullfilling condition X, select only result with smallest column value A”
I have a table with data and dates like so:
DECLARE @p TABLE (P_key int, P_Data char(1), P_ValidUntil datetime)
INSERT @p VALUES (20, 'T', '2003-02-28')
INSERT @p VALUES (21, 'U', '2005-05-31')
...
0
votes
1answer
53 views
Order of where clause evaluation
If I have a MySQL table which has content from the last 3 months I actually do the following:
SELECT SQL_BUFFER_RESULT SQL_CACHE count(id) cnt
FROM `mDelivered`
where _campaign = 2
and `session` = ...
0
votes
1answer
43 views
Why this query returns rows that I don't want to be there
I'm trying to running this query:
SELECT *
FROM
(`default_users`)
LEFT JOIN `default_profiles` ON `default_profiles`.`user_id` = `default_users`.`id`
WHERE
`default_users`.`group_id` ...
0
votes
1answer
1k views
How can I select the latest record having one state where no later records exist with any other state?
I want to select the last record (by datetime) having a given state where no later records exist with any other state for each given "widget".
widget state timestamp
------ ----- ...
0
votes
1answer
73 views
How to run a SELECT query within while loop in PHP?
Within a SELECT query via PHP while loop, I need to run a mysql SELECT query as
$result1 = $mysqli->query("SELECT * FROM table1");
while ( $row = $result->fetch_assoc() ) {
if ( $row['X'] == ...
0
votes
1answer
19 views
Delete from table where multiple fields match select subquery from other table
I want to delete an entry in a table where multiple fields match the results of another select subquery which takes data from another table.
This is what I have so far, though it doesn't work:
...
0
votes
2answers
95 views
SELECT only values THAT are different
I have two instances user1 and user2. They have colors
u_id | color<br>
1 | red<br>
1 | green<br>
2 | red<br>
2 | blue<br>
I need a mysql request, that ...
0
votes
0answers
24 views
table(s) sync question [closed]
i have a sync script that queries several different wordpress databases every 15 minutes to keep a main "feed" table up to date. it totals approximately 50,000 queries (99% of them are Selects, for ...
0
votes
0answers
39 views
mysql select query optimization [duplicate]
Possible Duplicate:
mysql select query optimization
I have two tables, testa and testb.
CREATE TABLE `testa` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) DEFAULT NULL,
...
0
votes
0answers
57 views
Informix Benchmark select
I'm not very familiar with databases and need your help. We have following case. Informix DB is running and target table contains 1.5 million records. We want to run application which periodically ...
0
votes
0answers
86 views
Being careful about additional records being added in a duplicate record merge?
We have a multi-user MS-Access 2003 database. Connecting to it using SQuirrel SQL, and the JDBC/ODBC bridge, I've managed to eek transactions of some sort out of JET by turning off autocommit. I've ...
0
votes
0answers
99 views
Can I use MySQL to check for multiple patterns with related elements (like S=2,M=4,L=2)?
Just wondering if this is possible to do in MySQL:
I have two search fields where users can search for sizes&quantities, for example:
S=2, M=2, L=2, XL=4
Right now I'm doing a big construct ...
0
votes
0answers
164 views
PostgreSQL Function PERFORM [closed]
CREATE OR REPLACE FUNCTION "insertarNuevoArticulo"(nombrearticulo character varying, descripcion text, idtipo integer, idfamilia bigint, artstock integer, minstock integer, maxstock integer, idmarca ...
-1
votes
3answers
105 views
Add Contents in a Column and make them 0 [closed]
http://sqlfiddle.com/#!3/96f11/3
In the above fiddle, I need the required output in the Fiddle.
ie., The UserID column in Filtered Table and Main table are equal.
I need to get the Amt column data ...
-1
votes
2answers
65 views
How to do division from select statements in sql server?
I am trying to create a select statement that can return a table of 1 column.
Basically, I am looping through all the records of NewHire, and then using its id, to select stuff from another table. I ...
-1
votes
2answers
120 views
Select query having count and variable
I have a table like the one below.
I need to form a select query. I'm going to pass a RefID like
SELECT SNo FROM Register WHERE RefID = 1
And beside the SNo in the Statement, I need to have ...
-1
votes
1answer
77 views
Optimization of a select statement
I'm using MySQL and have a table user_data like this:
user_id int(10) unsigned
reg_date int(10) unsigned
carrier char(1)
The reg_data is the unix timestamp of the ...
-3
votes
1answer
311 views
Best practices for finding and updating a handful of records?
Seems like a simple question, but wondering what is the "best" way to do this if you were "dotting your i's and crossing your t's".
-4
votes
2answers
170 views
Get Hierarchial Data in Self-Referencing Table (Parents , Childs) [closed]
In the following Fiddle,
sqlfiddle
I will pass a sno and I need all the parents of that sno in a table. And all the children of that sno in another table
Please refer to this question. Since ...
