Skip to content

Tag: mysql

Randomly Assign Rows in Child Table to Row in Parent Table

Using MySQL, I am trying to randomly assign rows in a child table to point to a row in a parent table, per following: Parent table: There are 50 WorkGroups (Team Alpha, Team Bravo, etc.), each of which can have a maximum number of WorkEmployees. Child table: There are 2,000 WorkEmployees (Ann, Bob, Carl, etc.…

MySQL 3 tables with 2 join and 1 non join table in one query

Good day, Having problems with querying this type of scenario. Sample scenario: I have 3 tables named tbl_customer, tbl_amount, tbl_expense tbl_customer has fields named customer_id, name, address, date_added tbl_amount has fields named amount_id, customer_id, amount, date_added tbl_expense has fields named e…

SQL Select Duplicate Values based on Specific Condition

I am asking for a solution where I can find duplicate entries in a table but one of those duplicate entries MUST contain a specific value otherwise it won’t come in the result. For example, my table is like this: ID Name Type 1 Hassan Commercial 2 Ahmed Personal 3 Jack Personal 4 Hassan Commercial 5 Jac…

What am I getting wrong in this SQL query?

Write a query that retrieves only a ranked list of the most prolific days in October 2020, prolific measured in number of posts per day. Your query should return those days in a single-column table (column name post_day) in the format YYYY-MM-DD. This is my table: This is my query: The problem is that I&#8217…

Data inconsistencies between two tables

I have an SQL question in which I am struggling to understand and find relevant resources to help me. The question is: “Write an SQL query to identify data inconsistencies between two tables.” I need to compare the following tables of data: AssetManager AssetManagerName John Doe Joe Smith Dave Gre…

With which order SQL update rows

Let’s say for example we have the following table: Salary table: id name sex salary 1 A m 2500 2 B f 1500 3 C m 5500 4 D f 500 If I write such query that swaps values from the column sex where m should be f and f should be m this query works: I’m used to some

Need to combine and get results

I’m trying to do the following: I want to minus the amount of RMAs from Sales: This is the query I did for Sales: This is the one I did for RMAs: I would like to take the results (let’s say 5000 sales and 3000 rma) and return a formatted result. Can you please help? Thanks!! Answer You can jojn

SQL: How to search set datatype by array?

I want to know if the data exist in set datatype by using an array. For example: The table is $role = [‘a’] SQL = SELECT * FROM … WHERE $role in role (have ‘a’) And the result is Or $role = [‘a’,’b’] SQL = SELECT * FROM … WHERE $role in role (have &#…