Is there any way to put WHERE filter inside the SELECT statement in 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 last year.
Improve this question
I got a task that i need to know how can i put WHERE clause inside the SELECT statement (like SELECT .... WHERE.... FROM...) . hope you guys could help me. thank you :)

'Where' is used to filter the data based on a condition.
The general syntax is:-
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Here you can get a better overview.

Related

A newbie in SQL asking about functions [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 6 months ago.
Improve this question
How can I find data that dont end with letter 'g' without using NOT LIKE function, please help
select * from table where right(column, 1) != 'g'
Since you asked how to do it using "not like," I'll answer that. The function version provided by #Zoories would be more efficient.
This works at w3schools.com
SELECT * FROM Customers where CustomerName not like '%g';

How to use LIKE operator on a subquery(returning multiple values) inSQL Server [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
SELECT *
FROM Products
WHERE Industry IN (SELECT *
FROM STRING_SPLIT('Logistics;Retail;Agriculture', ';'))
Can I use LIKE instead of IN in my WHERE clause?
You could use LIKE as follows:
SELECT *
FROM Products
WHERE ';Logistics;Retail;Agriculture;' LIKE '%;' + Industry + ';%';
But it would be better to see if you can use a WHERE IN (...) construct, which would be sargable, easier to handle, and probably more performant than the above.

SQL group by - can it be this simple? [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 4 years ago.
Improve this question
can someone please check if this is correct?
Not sure if my answer to Q6 is correct, I am not sure if the group_by I am using is right or not, the rest I think is ok
Thanks
You are close. You need to:
Use COUNT() instead of SUM().
There's no need to use the HAVING clause.
Optionally, you can add aliases to the columns, so they become easier to read.
Your query should look like:
select a.author_id, count(*) as titles, sum(b.quantity_ordered) as units
from a join b on a.book_id = b.book_id
group by a.author_id

how to merge a row data into above row..?which have few column same [closed]

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 7 years ago.
Improve this question
I have a table like.
And i want to answer like a table below:-
I think you want to use aggregation, like this:
select empcode, coode, finyear, wef,
max(cl_opn_bal) as cl_open_bal,
. . .
from table t
group by empcode, coode, finyear, wef;

How to check if one table is replica of other table in 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 7 years ago.
Improve this question
How to find if one table is replica of other table in SQL
In SQL Server, you can compare the results of:
SELECT checksum_agg(checksum(*))
FROM Table1;
SELECT checksum_agg(checksum(*))
FROM Table2;
You could create a join with these as sub-queries if you want, too.
You may wish to use binary_checksum() instead of checksum(). The doc says that checksum() will treat strings that are equal as equal according to the collation (i.e., 'hello' and 'HELLO' if the collation is case-insensitive), while binary_checksum() compares the raw binary values of characters.
This works for MySQL:
CHECKSUM TABLE table_1, table_2;