Skip to content

SQL Merge Into with multiple statements

I’m trying to keep a historic table of another one. When updating the original I would like to insert rows into the historic one. I’m using Sql Merge: Can I make multiple statements in the same “when” condition?, as such: Answer Normally you can INSERT only into one table. The syntax d…

Can I combine more than one function in a single line in SQL?

What I want to do is simply to use more than 1 function in a single query. I’m new to SQL so I’m sorry if I’m getting some words wrong. select cognom from emp where length(cognom) = 10, replace(cognom, ‘ ‘, ‘*’); Answer Yes, you can, as long as you respect the syntax.…

Search SQL database with multiple filters

I have the following code: This gives me the rows where “category_id” is equal to the 1. I now want the SELECT statement to return rows where the “category_id” is equal to one of the values I give it. So a simple SELECT statement would look something like this The problem is that I wou…

SQL query for last 365 days report

I have a reports table with the following structure : I want a SQL Query to get the report for the last 365 days by following conditions : Group dates if the same date is repeated. The days which the report is not available for the last 365 days, I need those days added to the result rows with 0

Removing count column from query output

Bsically, I’m trying to get the top 5 most rented but don’t want the actual count column as output only as a means of ordering the output. Is this possible? Answer You can try remove the count column and give the formula to order by part: My test: Select for MS SQL Server 2017: Output: col1 A B

Check if string contains user-defined substring using SQL LIKE operator

Basically I have a table like this: movieId name 1 White chicks 2 Inception 3 The Avengers: Endgame 4 Avatar: The Last Air Bender My job is to retrieve all relevant movies based on a substring of the movie name. For example, if a user enters a substring such as “av” (e.g., they enter “http:/…