Skip to content

Tag: mysql

Three table join with matched and unmatched records

I have three tables: store article_to_store article table. I need all articles with the store name. For all articles, I want to list all stores store table contains 3 stores. article table contains 2 articles. article_to_store relation table maybe has 2 records. One article in 2 stores. I need a mysql query w…

SQL GROUP BY IN CASE STATEMENT

i have one table i would like to classify the apple as below i try to add code as below, but its not like what I expected I try this code also, but got error Answer You want conditional aggregation here, which involves summing over the CASE expression:

Select corresponding column based on columns

In MySQL, I try to select a corresponding value based on the greatest value between columns. Let’s take as example table ‘prices’: id supplier price1 quantity1 1 Microsoft 8,27 1000 1 Apple 10,25 2000 1 IBM 12,25 3000 2 Microsoft 9,45 2000 2 Apple 7,55 4000 2 IBM 6,78 6000 The result I inten…

How to show pivot data without directly using pivot statement?

I am trying to pivoting the data without directly using the pivot function. I have a simple table t1 which has: My expected output is: I want to achieve this without using pivot. I tried using: How can I achieve the output without pivot? Answer You are sort of there, try the following: See Example Fiddle

How to list 3 largest numbers from table in SQL?

I’m trying to unite two bits of SQL codes and list three largest numbers from it. Here is table relation diagram Query #1: Query #2: My final code shows the full list of all first and second names, simply adding largest number to all of them from orders table. How can I modify it to make it show three n…

MySQL- Find records with overlapping period

I have a table hotel_booking reference start_date numberOfDays ABC 11-08-2021 2 DEF 12-08-2021 2 GHI 13-08-2021 3 JKL 10-08-2021 2 So the first task I wanted was to get all bookings which has startDate between x and y date which is straight forward query This returns me ABC and DEF which is perfect. Now I wan…

Strange variables MySQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 11 months ago. Improve this qu…