I use MySQL 5.6 and I have 3 tables. Two of them are a list of data, and the third table is used for a relationship between them. In the third table I would like to identify a default record for each id1, so I added a column named predt to let me know which record is the default one.
Tag: mysql
SQL: Returning a list of unique values with respect to another value
I have a table that tells me the products as well as which state they’re sold in. PRODUCT | STATE ————————————————- yPhone | Alabama yPad | Massachusetts …
sql clauses using HAVING truncated value error for part of the string
I am getting an integer value error but don’t understand why. Warning: #1292 Truncated incorrect INTEGER value: ‘%accepted%’; Warning: #1292 Truncated incorrect INTEGER value: ‘%pending%’ . It does not have the error for processing. It doesnt matter what is in “1st position…
Count date if it is in the same months as the first order of the customer
DB Fiddle Expected Result My database consists of two tables returned and customers. In the customers table you can find the date of the first_order per customer. In the returned table you can find each return a customer has done so far. Now, I want to create a list and count all returned_dates which are in t…
Finding Similar People’s Names from Database
I have a table in MySql with names in it. I am trying to, given an input name, find all similar names in the table. I’ve heard a lot about Levenshtien/Damerau–Levenshtein distance, but it doesn’t seem like it would work well for this, I’ll explain my reasoning later. To elaborate: User input…
mysql count from table where related record exist in other table
I have 2 tables, customers and addresses. I want to count how many customers have addresses with name like a given search term something like SELECT COUNT(*) as countSearch FROM customers,addresses …
Mysql When then and temp variable. Explanation
I have this sql query that I am trying to understand. Can I get a line by line explanation please. I know the first line Initialise variable. Second line gets the minimum value. Answer The variables are enumerating the rows for each occupation separately. You can see this by running the subquery to see the re…
How to merge rows in sql
I am trying to understand how to merge two rows (which are the same) into one. They both have data that needs to be in the same row but the raw data currently has split them into two rows. Essentially,…
Create a left join with raw string data
I have a list of e-mails in a text file and a Person table with an email column. I need to know which of the emails are in the table, and which are not. So I was thinking in creating a query and do some kind of left join in my raw e-mail data with the Person table. Now, I
elect data from related tables with duplicate columns
I have 3 tables. news rubrics parent_id is key for id parent in table rubrics. And “news_rubriks” How I can select news which apply to rubrics.id and rubrics.parent_id ? Answer If I understand correctly, you want to apply a filter to both the rubrik id and the parent. Say if you are searching for …