Skip to content

Tag: mysql

MySQL self join but in the same row

I have this table: date sku note 11/12 123 note 11/13 123 note 11/12 456 note 11/13 456 note 11/12 789 note 11/13 789 note (Note is random) And I want the result to return this: date sku note sku note sku note 11/12 123 note 456 note 789 note 11/13 123 note 456 note 789 note I tried self

SQL multiple left join as new columns performance

I have 3 tables : account id name 1 Google 2 Apple custom_field id name 1 Phone 2 Email custom_field_submission id custom_field_id entity_id value 1 1 1 555-444-333 2 1 2 111-111-111 3 2 1 google@goog.com 4 2 2 apple@apple.com Expected result after query id name Phone Email 1 Google 555-444-333 google@goog.co…

Omit rows where multiple columns contain NULL

I’m trying to figure out how to build a query that omits rows where both columns of interest are NULL. If only one or the other is NULL, then I would like to include that data. In this example table, I would like to have a query that includes everything except row 3. My thought would be to build a

SQL query for all grouped records in joined table

Let’s consider a toy example. There is a table employees and table tasks, where each task is assigned to one employee. One employee can have multiple tasks. I want to query employees filtering them by some columns in their tasks. I group the employees to display each one only once. The query would be so…

Error in sql syntax value ? but it’s showing the value?

the title isn’t very specific but I don’t know how to make it better. I’ve got this error in my sql telling me something is wrong but I don’t understand why it’s wrong, currently using mysql 8.0.24. If you wonder why it looks strange it’s because I use it in lua Sql: Error:…

SQL group by return null if one is null

I have orders table that have delete marker column date_deleted which value is null or date order_number item_id date_deleted 111 aaa null 111 bbb null 111 ccc 2021-x-x I have query to select the fully deleted orders with group by order_number It give me this result order_number date_deleted 111 2021-x-x Whic…