Skip to content

Tag: sql

DELETE entry that is older than current datetime in MySQL

I have tried the following among various other statements but thought one of these should obviously work but no luck so far. Please tell me what I’m doing wrong. Not getting an error, it’s just not working. DELETE FROM table_name WHERE from < NOW() DELETE FROM table_name WHERE from < ‘2022-04-16 08:00:00’ Example Answer You shouldn’t name your columns (or

SQL Where statement for strings

I have a column that’s string and I would like to use a WHERE statement for all strings that begin with the “sea_” Any ideas on how to achieve that will be appreciated. Thanks in advance Answer It’s not clear what exactly your where clause should do. If necessary, you should please add more information. Anyway, in general, you can

SQL write a query, question from interview problem

At the beginning I need to mention that I am not very good at SQL so I would like to ask you. Here is a tables relation: tables What I need to do with them is “Show name, surname and number of movies those directors (Re┼╝yser means director), who made more movies that the average number is for all directors.

How can i filter a datetime column in informix with a date

I’d like to filter a datetime column in informix 12.10. I got the following “test” table name insert_date create_date … 2022-04-06 11:03:22.000 …. … 2022-03-02 12:03:22.000 …. … 2021-02-04 11:15:22.000 …. … 2021-01-05 11:03:22.000 …. My approach is the following I got the error: SQL-Error [IX000]: Non-numeric character in datetime or interval. How can i filter a datetime column with

Is the Function in the GROUP BY Clause Necessary?

I’m an Oracle newbie just trying to learn. Are the following two queries equivalent in terms of their results? Query 1 Query 2: No TO_CHAR() in the GROUP BY Clause I’m using Oracle version 12.1. Answer Both queries won’t return the same result… unless customers.date includes only dates with no time part. The DATE type in Oracle includes the date

How to use this laravel query builder for this SQL Query

I have this query: SELECT `topic_posts`.*, `users`.`id` AS `adminID`, `users`.`name` as `adminName` FROM `topic_posts` INNER JOIN `topics` ON `topics`.`id` = `topic_posts`.`topic` INNER JOIN `users` ON `users`.`id` = `topic_posts`.`player` WHERE `users`.`playerAdminLevel` > 0 AND `topics`.`type` = 0 GROUP BY (`topic_posts`.`id`) And I want to use in Laravel, something like: $result = DB::table(‘topic_posts`)->join..etc And also, to use ->paginate(20) How can I do

How to change my name into columns using sql

What is the best query to split name into columns? ie. if my name is VELOCITY in one column. How can i split it as Answer If you just have a single row then: Which outputs: CH V E L O C I T Y If you have multiple input rows then, from Oracle 12, you can use a LATERAL

Repeating JSON Aggregated Array with Row Limits

I have an Oracle 19 database with a JSON aggregated array which I need to cut off and repeat after a set number of rows, for example: …etc. Here’s some basic SQL to illustrate how my current dataset is put together: I need to push customer data to an API endpoint. Pushing 1 customer record at a time is not