I have this table: create table products(name text, quantity int); insert into products values (“A”, 10); insert into products values (“B”, 0); insert into products values (“C”, 15); insert into …
Tag: mysql
SQL – Compare 2 tables with dates [closed]
I have 3 tables with are the following: st with an id, startDate, endDate, customer_id and serivcedeal_Id. servicedeal with id and name. price with id, price, startDate and servicedeal_Id. I have …
How to store tags for a blog article in SQL database?
I currently am working on developing a blogging website. For this application we’re using MySQL as the database. For this application,I created a blog table which contains the following properties: id blog_title content user_id updated_at upvotes I want to add tags to this table. What is the recommended…
Symmetric Pair in SQL with JOIN
I am trying to find the name of students where a symmetric pair exists. There are 3 tables: Edit from your comment: A student is called as being a part of a symmetric pair if the marks obtained by that student in science is equal to the marks obtained by some other student in mathematics and the marks obtaine…
select starting digitals followed by first word in mysql
I have lots of addresses in my database. example: 1199 State Route 218 I want to select the starting digitals followed by first word and ignore the rest of the address. so i want to retrieve address just by calling this: 1199 State thanks for you help Answer If you are running MySQL 8.0, you can use regexp_su…
Generate series of random size data in MySQL
I need to populate table with random size of data for each dependency record. First table is table of products (named products): And the second table is table that contains displays of that product (named product_displays). Each display is another row: Like you can see date will always be the same value, but …
behavior of DBMS after executing where clause
in a select query when some records doesn’t satisfy the condition in where clause, they will be omitted for executing subsequent clauses or not? for example consider we have a group by clause and after that, we have a condition in having clause on max(someThing). if a record has the maximum value of pro…
Select the last record in MySQL in WHERE condition
I have a table that store ticket and statue relation I want to select rows that last status_Id equal 2 ,Rows are marked in table. I think I have to use GROUP BY on column ticket_Id but it return with first status_Id. Answer This problem is a good candidate for ROW_NUMBER: The above logic finds all latest rows…
Filter duplicate records and retain 1 record
I was able to get the duplicate records and I wanted to retain 1 record per item barcode based on the createdate (oldest) sample script of getting the duplicate records: output: final output should be like this: (retain the items that has the oldest createdate from the 2 duplicate Barcodes) Answer I guess you…
How to make it to select from 1st day every month
Hello there I have a question so I have a goal mysqli query and it sum the price and select by interval 1 month I try few things to made it to select only from 1st day of the month but I have no idea …