Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last year.
Improve this question
I have 2 tables like below
here i need to get all the rows from second table based on each row from the first table which matches Field1value and field2value combination.Second table select column will decide by first table field1 and field2 respectively,and I need to remove the duplicate row if any,for example last row in second table satisfies the condition of 1 and 3 row of first table.
How to format this query?.
Are you looking for something like this?
select 'select distinct percentage from table2 where '+Field1+' ='+ ''''+Field1value+ ''''+' and '+Field2+' = '+ ''''+Field2value+ '''' from table11
result:
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
I need to do an union between 2 tables and there is a column on the first table that doesn't exist on the second table, so, I would like to set up a column with null's (e.g: select null as column_name from table2). However, it involves a SUM and I can't use "null as Sum(column_name)" since it doesn't work. Since the values are null, the sum would be 0.
So, how do I select a sum from a column that doesn't exist in a table but I will insert null values on that column?
In your union, when you select from the table that does not have the column in question, just include null as <column name> in the appropriate position in your select statement. Or you could do 0 as <column name>, whatever works better for you.
You could apply ZEROIFNULL around that column to make them 0.
SUM(ZEROIFNULL(UnionColumn)) This should work fine with Teradata.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I need to select distinct records from table and perform a sum of columns (Pallats, Gross) of a duplicate row. And show duplicate rows only once.
Input Table data:
Output of SQL:
You seem to want aggregation:
select disport, actualagent, . . . , country,
sum(pallats), sum(gross)
from t
group by disport, actualagent, . . ., country;
You need to list all the columns where the . . . is.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two tables, one big and one small. Both contain columns ID and EffectiveDate.
The bigger table has more other columns and of course more rows than the smaller table.
Under the condition that ID for both tables are the same, the EffectiveDate column is earlier in the small table than the big table. I want to replace the EffectiveDate in the big table by the value of the EffectiveDate column from the small table.
What should I do?
Seems like a very basic SQL query....
UPDATE bt
SET EffectiveDate = st.EffectiveDate
FROM dbo.BiggerTable bt
INNER JOIN dbo.SmallerTable st ON bt.ID = st.ID
-- maybe you also need this condition, if not *ALL* EffectiveDate values in the
-- smaller table are indeed before the values in the bigger table
WHERE st.EffectiveDate < bt.EffectiveDate
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a list of over a million numbers. I need to put the numbers in one table numerically sorted, and another as is, referencing the ID of the sorted number, the table is structured as so:
sortedNumbers
Id | SortedNumber
1 01356
2 45789
Numbers
Id | Number | SortedNumberId
1 35601 1
2 94578 2
3 97548 2
Currently I am filling the sorted numbers table first, then filling the standard numbers table, and doing a select statement to get the sorted numbers Id. All these select statements are making it dog slow though, is there a way to do it all in one statement, never using a select statement to get the Id of the sorted number?
Current Queries on each iteration of a loop, sortedNumber is made by sorting the number in code
loop 1
query = "INSERT into SortedNumbers VALUES (" + SortedNumber + ")";
loop 2
query = "SELECT Id FROM SortedNumbers WHERE SortedNumber = " + sortedNumber;
query = "INSERT into Numbers VALUES (" + Number + ", " + SortedId + ")";
Well for a start you don't put sorted numbers into a database. You put the numbers into a table then query the table ordering by whatever sort criteria you want.
SELECT number from table ORDER BY number
But I expect I've missed the point of whatever you are trying to do. Can you post some examples?
You could wrap your two inserts into a Transaction and get the ID value from the sortedNumbers table by calling SCOPE_IDENTITY(). That is assuming that the ID column in the sortedNumbers table is an Identity column:
BEGIN TRANSACTION
INSERT sortedNumbers (SortedNumber) VALUES (sortednumbervalue)
INSERT Numbers (Number, SortedNumberId) VALUES (numbervalue, SCOPE_IDENTITY())
COMMIT
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have two tables in my sqlite database, with a column name as in both tables solution, solutionimage, id saying tableA and tableB. I want to, copy from tableB solution, solutionimage to tableA matching the id in both table respectively, how to do it?
I have google it and tried but i didnt get it.. Any one help me. Thanks a lot in advance.
Ideally you would want to join the table you are updating to the other table where you take the values from.
But I just read that JOINS in UPDATES are not allowed in SQLITE so subqueries are the way to go I suppose:
UPDATE tableB
SET
Solution = (SELECT Solution FROM tableA WHERE ID = tableB.ID),
SolutionImage = (SELECT Solution FROM tableA WHERE ID = tableB.ID);
See this fiddle for example output.