Skip to content

Tag: mysql

SQL Query Sequential Month Logins

I have the following SQL table username Month 292 10 123 12 123 1 123 2 123 4 345 6 345 7 I want to query it, to get each username’s login streak in Count of sequential Month. meaning the end result I am looking for looks like this : username Streak 292 1 123 3 345 2 How can

How to use DateDIFF function in mysql table

I have a dataset in my library management system and I have used below query to get specific field only. now I need DATEDIFF function to get the date difference between today date and ReturnDate if there is no any receiveddate value.Further I dont need negative values as well. As an example if currdate()<T…

How to join tables without using join SQL

I’m trying to write a SQL query to grab information from multiple tables and output an end result: a list of all clients that have not placed a stock request yet. Displaying client number will be sufficient. I am not allowed to use inner join or any type of join to achieve this. So far this is what I ha…

How to make mysql function that return from the select result?

I want to create this function on mySql 8. It will create a sequence number like 00001,00002 i dunno whats wrong with this query but i always got this error. I also tried with this query. but still gave me with the same error. What could go wrong with my function query ? Answer Multiple datatype convertions a…

How do I find an order that contains all the available products?

I have a products table that contains all the available products, as well as the order_has_product table which contains all the products that should be included in every order. How do I find the order_id for any order that contains all the available products? Note how the order with an order_id of 1 contains …

How to use SQL to find specific names or words in a database?

I am working with a database of data from Reddit. I want to find the name and description of all subreddits where the name starts with “covid” or “corona” and the description contains “covid” anywhere. I then want to output a table that has two columns: name and description…

Find rows that have the same value and select the newer one

I got a table, that looks like this: serialNr sensorNr ModifyDate 1234 12EE56423 2022-04-06 4567 12EE56423 2018-06-12 6789 AD3FF0C44 2018-03-08 9101 AD3FF0C44 2019-06-07 From rows with the same sensorNr, I only want to select those with newer ModifyDate, so the result should look like this: serialNr sensorNr …