Remove sorting order differences while comparing 2 tables using sql [closed] - sql

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 2 days ago.
Improve this question
I am trying to compare cell to cell of 2 tables.
There is a situation wherein a record in column C is in row 4 of table 1 while same record is in row 7 in table 2.
Hence during comparison, record in col C and row 4 is giving a mismatch as it's not same in table 2.
In reality, such mismatches are to be ignored since it exists somewhere within table 2 but just in different row.
What is the best way to ignore such mismatches.
I am not able to get with Exist function syntax.
For example record in tbl1."Col C" is to be seen if available in tbl2."Col C" and if this record is not found, then the mismatch has to be reported.
I am not able to get right syntax here either for exist function or sorting 2 tables and then comparing.

Related

Update all rows to same value or update certain ones only? [closed]

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 1 year ago.
Improve this question
There's a table with one column "scores" and 10 rows in it. 2 rows have 10 scores, the other 8 have 0 scores. I want to set all rows' scores to 0. Which way is more optimized?:
UPDATE <table> SET scores = 0
UPDATE <table> SET scores = 0 WHERE scores <> 0
It depends entirely on the database you are using.
Some databases check to see if a value is changing before updating a row (and incurring the overhead of logging).
Some databases update all specified rows, even if the value doesn't change.
In general, though, I would use the WHERE clause. However, you do need to be careful about NULL values in that case.
And, for 12 rows, performance doesn't really matter.

Subtract two column values and store result in another column [closed]

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 7 years ago.
Improve this question
I have the one table eg tbl_1 and i have column eg A B C. When I insert into column A and B its result store into C like c=a-b.
If you wish to create virtual/computed columns while creating a table structure, Since you dint specified which RDBMS you are using, please following links (the one that suits you) :
Hope it helps you.
MYSQL
ORACLE 11G
SQL SERVER
CREATE TABLE tbl_1
(
A int,
B int,
C AS A - B
);

Divide all values but one in sql table [closed]

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 7 years ago.
Improve this question
i got this table, and i want to divide all the values on one of the columns except one.
I havent wrote any code about it just looking for an explanation on how to do it, if anyone could help out would appreciate.
In order to modify the content of one column in all rows except one, you can use the following query:
UPDATE tablename SET columName = columnName / 42 WHERE rowId !=42;
WHERE contains the condition that has to evaluate to true, in order for the update to take effect. My example modifies all rows except for those whose rowId column contains the value 42.

Efficeint way to check if 35K + rows are present in table X having 700000+ rows? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have 35K+ records (say column A) in a flat file. I have to check if these records are already present in table X (having 700000+ records)
Column A is not an Indexed column in Table X. I do not have any column in Flat File which is indexed in X.
-I can't use the IN operator in SELECT because it is not a feasible option for 35+ records ( costly and limit being 1K)
- All the records have a similar pattern so I tried pattern match using LIKE operator in SELECT but it is very inefficient. ( the number of records with similar pattern in X is 120000+)
- I do not have create table privilege to insert in new table and subtract etc.
I am new to Oracle sorry if this question is naive. Also, I searched for similar questions and could not find answers for non-indexed columns.
Could someone please help me?
Flat file means text file like CSV or TSV? If it's just a text file, load it into database. Perhaps you can create a temporary table for this job. Then you can use the following query:
select *
from x
where (c1, c2, ...) in (select c1, c2, ... from a);

SQL Select and sort on relevance [closed]

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 want to search an table column. and select all rows that contains a string.
I do that on this way:
select * from memos where contains (article, '"test*"')
The next problem is to order the acticles on relevance. So if a record contains 4 times the word of wordpart 'test' i want it on top and if it contains 3 times the word 'test' i want it below 4. And so order it on how many times a word is in a row.
Assuming the article is stored as a varchar() or nvarchar(), then you can do this
select *
from memos
where contains (article, '"test*"')
order by len(replace(article, 'test', 'test1')) - len(article) desc;
This replaces test with a string one character longer, measures the length, and then subtracts the original length. Voila. The number of times that test occurs. This should take place only on articles that have the search term.
I'm not sure if SQL Server has something like this built-in to the full text engine.