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

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);

Related

Remove sorting order differences while comparing 2 tables using sql [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 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.

Best way to compare and update two SQL tables [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 7 years ago.
Improve this question
What is the best way to compare two tables lets say SourceTableA and DestinationTableB?
if data found in DestinationTableB but not existing in SourceTableA,
insert them to SourceTableA
else if data found in SourceTableA but not DestinationTableB, delete
them from SourceTableA
You should to use MERGE statement to do this.
MDSN - SQL Merge
Those two condition are mutually exclusive so you don't need an else
delete SourceTableA
where not exist (select 1 from DestinationTableB
where DestinationTableB.key = SourceTableA.key)
insert into SourceTableA
select *
from DestinationTableB
where not exist (select 1 from SourceTableA
where DestinationTableB.key = SourceTableA.key)
Relevant
This is very vague, but the best choice would probably to run 2 queries, one that delete from A where it doesn't exist in B, then one that inserts B into A where it doesn't exist in A.

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
);

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.

Sqlite: I need to update a data from one table to another [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 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.