SQL Select and sort on relevance [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 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.

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.

How to pull list of all the customer with first_name as alphanumeric value [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 years ago.
Improve this question
I have a table name clients, now I want to pull a list of all the customers having first_name as alphanumeric value as an example, jriqbal23, sam45del etc.
If I need to pull the details of single customer, I can run below SQL:
select customer_id,email,first_name,last_name,middle_name from clients
where
email='jriqbal23#gmail.com';
how to change this query for pulling the list of all the customer having first name in similar way ?
thanks in advance.
If you use Oracle database, you can query client data with regexp_like:
Alphanumeric case:
select *
from clients
where regexp_like(first_name, '\w+');
Digits case:
select *
from clients
where regexp_like(first_name, '\d+');

Calculate number of exercises in each category in access 2016 [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 5 years ago.
Improve this question
I have two tables such as: Category and Exercise. In the first of them I have field names such as: CategoryID and CategoryName. In the second table there are field names such as: ExerciseID Exercise and CategoryID. I have to calculate the number of exercises in each category. For the exercises with provided data I have:
addition, subtraction, multiplication, division, enhancemen,
running, jumping, pole vault, shot put, literature, grammar.
The query has to output me:
Maths = 5
English = 2
PE = 4
How would I be able to calculate this within query in ms-access?
You should have a key to join the tables.
In addition to ExerciseID and Exercise, have a CategoryKey column which you can join to the Category table through CategoryID. Then you'd just query SELECT COUNT(*) as count FROM Exercise WHERE CategoryKey = 1 where 1 is the CategoryID you want to count. You can also do more complex joins in the future if you have new requirements.
Otherwise, you'll have to write a giant goofy sql switch statement, which I don't have much experience with, because it's usually not something you need to use if your table is structured correctly.

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