I'm trying to get the results from this question (SO 2429348 - Help with a SQL query) except I need it to return values 1 and 3.
Edit: GROUP BY loses all except the first unique value, so replacing min with max will not work.
Edit: I didn't want to show what I'm working with but I guess I will:
Here is the table called 'test_posts'
I...
I'm trying to set up a query that shows the first post of each thread and is ordered by the date of the last post in each thread. I got the first part down with this query:
SELECT *
FROM (
SELECT Min( ID ) AS MinID
FROM test_posts
GROUP BY Thread
)tmin
JOIN test_posts ON test_posts.ID = tmin.MinID
Now I need to figure out how to cal...
Is it possible to update the same view with new data? Using UPDATE after CREATE didn't seem to work.
Have only 1 table. Want the view to be a subset of that table. After using the view, I would like the same view to hold a different subset of the data from the only table.
Was thinking I can create the view, drop it, then create it ...
Hi,
I have a Microsoft Notepad flate file with data and Vertical Bar as column delimiter.
I get following message: cannot convert between unicode and non-unicode string data types
It seems it is my nvarchar(max) that creates my problem.
I changed to varchar(max); but still the same problem.
And in the SQL Server 2005 import and expo...
I have a query that gets a list of emails who have subscribed for a newsletter trial which lasts 30 days..
$thirty = time() - 3024000;
SELECT c.email
FROM tbl_clients AS c
JOIN tbl_clientoptions AS o ON o.client = c.id
WHERE o.option = 'newsletter'
AND c.datecreated > $thirty
What I want to do is do a check in that same q...
I have table 'products' and I need to update 'price' field by 20% if product 'type' field is "imported".
How do I read and update field at the same time in my UPDATE query?
...
I'm trying to select a record with the most effective votes. Each record has an id, the number of upvotes (int) and the number of downvotes (int) in a MySQL database.
I know basic update, select, insert queries but I'm unsure of how to form a query that looks something like:
SELECT *
FROM topics
WHERE MAX(topic.upvotes - topic.dow...
Is there a way to copy View output column headers along with the data? There is a setting in Options to include column headers with query results, but that only works with "New Query" and Stored Procedure output.
Looks like SSMS 2008 has this functionality built in to the contextual menu when you right click on results, but I only have...
Could anyone tell me how to bulk insert data from a ref cursor to a temporary table in PL/SQL? I have a procedure that one of its parameters stores a result set, this result set will be inserted to a temporary table in another stored procedure.
This is my sample code.
CREATE OR REPLACE PROCEDURE get_account_list
(
type_id in account_t...
I have a table with four Columns: Col1, Col2, Col3, and Col4.
Col1, Col2, Col3 are strings, and Col4 is a integer primary key with Auto Increment. Now my requirement is to have unique combination of Col2 and Col3.
I mean to say like.
Insert into table(Col1, Col2, Col3) Values ('val1', 'val2', 'val3');
Insert into table(Col1, Col2, Col...
Hi!
I have people, companies, employees, events and event kinds. I'm making a report/followup sheet where people, companies and employees are the rows, and the columns are event kinds.
Event kinds are simple values describing: "Promised Donation", "Received Donation", "Phoned", "Followed up" and such. Event kinds are ordered:
CREATE T...
I have the following tables in a database (i'll only list the important attributes):
Person(ssn,countryofbirth)
Parents(ssn,fatherbirthcountry)
Employment(ssn, companyID)
Company(companyID, name)
My task is this: given fatherbirthcountry as input, output the names of companies where persons work whose countryofbirth match the fatherbi...
What is indexing?
What is full text?
I know the answers to both questions, but I can't expose those answers in the exact way to an interviewer:
indexing means something like index in book
fulltext means for search string
Can please give me very simple definition for each of these questions?
...
i want to know, how to write subquery in between SELECT and FROM as
SELECT Col_Name,(Subquery)
From Table_Name
Where Some_condition
...
I have an access table which has some cells as blank ( no data ) in a particular column.
how i write an sql query to replace a blank cell with any text in access 2007 column
any help appreciated.
i have already tried the sql query
update tableA set colA = 'abc' where ISNULL(colA);
It updates 0 rows.
...
The following query works on Oracle 10.2.0.1.0 on windows,but doesn't work on Oracle 10.2.0.2.0 on Linux.
Error report:
SQL Error: ORA-00904: "T"."AUDIT_USECS": invalid identifier
00904. 00000 - "%s: invalid identifier"
It works after i remove the sub-query. I found that if use fields of T in sub-query,then error occurs. Is it saying...
Have a lot of unnecessary results using contains() method in my query. Don't tell me to use like or something else. It is hardcoded and couldn't be changed.
...
Hello all,
I'm working with three tables, and for simplicity's sake let's call them table A, B, and C. Both tables A and B have a column called id, as well as one other column, Aattribute and Battribute, respectively. Column c also has an id column, and two other columns which hold values for A.id and B.id. Now, in my code, I have easy...
Hi !
I have a table with many rows, is there any way to find out when a concrete row has been inserted? (I don't have create/update time columns)
Thanks
...
When using the folllwing to create the command:
_command = new SqlCommand(statementOrProcedure, _connection) { CommandType = CommandType.StoredProcedure };
and the stored procedure requires no input parameters, it works fine.
As soon as the stored proc needs input parameters, I do the following:
private void AddStoredProcedureParame...