inner-join

SQL query to find partial string match across 2 tables

自古美人都是妖i 提交于 2020-08-20 12:42:15
问题 I'm trying to find any items in column address (users table) that have a match in Address (address_effect table). I'm testing this on my local system with XAMPP (using MariaDB) user table +------------------+-----------------+------------------+--------------------------+ | ID | firstname | lastname | address | | | | | | +----------------------------------------------------------------------------------+ | 1 | john | doe |james street, idaho, usa | | | | | | +---------------------------------

SQL query to find partial string match across 2 tables

被刻印的时光 ゝ 提交于 2020-08-20 12:41:06
问题 I'm trying to find any items in column address (users table) that have a match in Address (address_effect table). I'm testing this on my local system with XAMPP (using MariaDB) user table +------------------+-----------------+------------------+--------------------------+ | ID | firstname | lastname | address | | | | | | +----------------------------------------------------------------------------------+ | 1 | john | doe |james street, idaho, usa | | | | | | +---------------------------------

MySQL: query with two many to many relations and duplicates, with full data from subqueries

北慕城南 提交于 2020-08-08 09:59:25
问题 This question extends one I just asked, and that was just solved here: https://stackoverflow.com/posts/62861992/edit But there is need for a new question, as there is one detail that was missing in the other one. But first things first. I have four models: articles , authors and tags . Each article can have many authors, and also can have many tags. So my DB will have the following tables: article article_author author article_tag tags Here in MySQL: DROP TABLE IF EXISTS article_tag; DROP

MySQL: query with two many to many relations and duplicates, with full data from subqueries

江枫思渺然 提交于 2020-08-08 09:59:01
问题 This question extends one I just asked, and that was just solved here: https://stackoverflow.com/posts/62861992/edit But there is need for a new question, as there is one detail that was missing in the other one. But first things first. I have four models: articles , authors and tags . Each article can have many authors, and also can have many tags. So my DB will have the following tables: article article_author author article_tag tags Here in MySQL: DROP TABLE IF EXISTS article_tag; DROP

Updating table based on the results of previous query

老子叫甜甜 提交于 2020-07-20 03:47:30
问题 How can I update the table based on the results of the previous query? The original query (big thanks to GMB) can find any items in address (users table) that have a match in address (address_effect table). From the result of this query, I want to find the count of address in the address_effect table and add it into a new column in the table “users”. For example, john doe has a match with idaho and usa in the address column so it’ll show a count of ‘2’ in the count column. Fyi, I'm testing

Updating table based on the results of previous query

夙愿已清 提交于 2020-07-20 03:47:01
问题 How can I update the table based on the results of the previous query? The original query (big thanks to GMB) can find any items in address (users table) that have a match in address (address_effect table). From the result of this query, I want to find the count of address in the address_effect table and add it into a new column in the table “users”. For example, john doe has a match with idaho and usa in the address column so it’ll show a count of ‘2’ in the count column. Fyi, I'm testing

MySQL Select rows that match multiple rows in related table

痴心易碎 提交于 2020-07-06 20:21:34
问题 The following tables are much larger, but have been downsized for ease of the question Table 1 - exercise_rolladex Exercise_ID | Exercise_Name --------------------------- 1 Pushups 2 Turkish Get Ups 3 Squats 4 Ice Skater Table 2 - exercise_planes Exercise_Plane_ID | Exercise_Plane ---------------------------------- 1 Sagittal 2 Frontal 3 Transverse Table 3 - exercise_has_planes Exercise_ID | Exercise_Plane_ID ------------------------------- 1 1 2 1 2 2 2 3 3 1 4 2 4 3 My question is: How can

Alias a table in Knex

淺唱寂寞╮ 提交于 2020-06-25 07:27:06
问题 I have a SQL query that refers to the same table twice, and I need to alias the table to two separate aliases. I can't quite figure out how to compose this with Knex. There's a 'Words' table and a 'Users' table. The Words table has two foreign keys, 'author_id' and 'winner_id', referencing the Users table's 'id' column. Here's the SQL I'm trying to compose in Knex: SELECT w.*, ua.name, uw.name FROM Words AS w INNER JOIN Users AS ua ON w.author_id = ua.id LEFT JOIN Users AS uw ON w.winner_id =