如果列包含子字符串,phpmyadmin 会给出连接 2 个表的语法错误
phpmyadmin gives syntax error to join 2 tables if a column contains substring
"mytest_people" 和 "mytest_hobbies":
PK FK <--- PK
+----+------+------+------+ +----+-----------------+
| Id | Name | Age | H_ID | | Id | Hobby |
+----+------+------+------+ +----+-----------------+
| 0 | Pete | 100 | 0 | | 0 | Reading News |
| 1 | Mark | 5 | 1 | | 1 | Reading Fiction |
| 2 | Bob | 33 | 3 | | 2 | Writing |
| 3 | Lulu | 12 | 1 | | 3 | Cooking |
+----+------+------+------+ +----+-----------------+
这是我期望得到的:
+----+------+------+-----------------+
| Id | Name | Age | Hobby |
+----+------+------+-----------------+
| 0 | Pete | 100 | Reading News |
| 1 | Mark | 5 | Reading Fiction |
| 3 | Lulu | 12 | Reading Fiction |
+----+------+------+-----------------+
这是日常用语/伪代码:
IN DATABASE "my_new_test_data_base"
SELECT COLUMNS "Id, Name, Age"
FROM TABLE "mytest_people"
WHERE COLUMN "H_ID"
EQUALS COLUMN "Id"
FROM TABLE "mytest_hobbies"
THEN JOIN COLUMN Hobby
FROM TABLE mytest_hobbies
ON CONDITION Hobby VALUES
CONTAIN 'Reading%' SUBSTRING;
这是我对 SQL 代码的最新尝试:
USE my_new_test_data_base
SELECT mytest_people.Id, mytest_people.Name, mytest_people.Age FROM mytest_people
INNER JOIN mytest_hobbies (`Hobby`)
ON mytest_people.H_ID = mytest_hobbies.Id
WHERE `Hobby` LIKE 'Reading%';
这是我得到的错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT mytest_people.Id, mytest_people.Name, mytest_people.Age
FROM mytest_peop' at line 2
一些小错误,每条命令都要以分号结束
别名不属于括号
USE my_new_test_data_base;
SELECT mytest_people.Id, mytest_people.Name, mytest_people.Age ,mytest_hobbies.`Hobby`
FROM mytest_people
INNER JOIN mytest_hobbies
ON mytest_people.H_ID = mytest_hobbies.Id
WHERE mytest_hobbies.`Hobby` LIKE 'Reading%';
如果您喜欢少打字:
SELECT p.Id
, p.Name
, p.Age
, h.hobby
FROM my_new_test_data_base.mytest_people p
JOIN my_new_test_data_base.mytest_hobbies h
ON p.H_ID = h.Id
WHERE h.Hobby LIKE 'Reading%';
"mytest_people" 和 "mytest_hobbies":
PK FK <--- PK
+----+------+------+------+ +----+-----------------+
| Id | Name | Age | H_ID | | Id | Hobby |
+----+------+------+------+ +----+-----------------+
| 0 | Pete | 100 | 0 | | 0 | Reading News |
| 1 | Mark | 5 | 1 | | 1 | Reading Fiction |
| 2 | Bob | 33 | 3 | | 2 | Writing |
| 3 | Lulu | 12 | 1 | | 3 | Cooking |
+----+------+------+------+ +----+-----------------+
这是我期望得到的:
+----+------+------+-----------------+
| Id | Name | Age | Hobby |
+----+------+------+-----------------+
| 0 | Pete | 100 | Reading News |
| 1 | Mark | 5 | Reading Fiction |
| 3 | Lulu | 12 | Reading Fiction |
+----+------+------+-----------------+
这是日常用语/伪代码:
IN DATABASE "my_new_test_data_base"
SELECT COLUMNS "Id, Name, Age"
FROM TABLE "mytest_people"
WHERE COLUMN "H_ID"
EQUALS COLUMN "Id"
FROM TABLE "mytest_hobbies"
THEN JOIN COLUMN Hobby
FROM TABLE mytest_hobbies
ON CONDITION Hobby VALUES
CONTAIN 'Reading%' SUBSTRING;
这是我对 SQL 代码的最新尝试:
USE my_new_test_data_base
SELECT mytest_people.Id, mytest_people.Name, mytest_people.Age FROM mytest_people
INNER JOIN mytest_hobbies (`Hobby`)
ON mytest_people.H_ID = mytest_hobbies.Id
WHERE `Hobby` LIKE 'Reading%';
这是我得到的错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT mytest_people.Id, mytest_people.Name, mytest_people.Age FROM mytest_peop' at line 2
一些小错误,每条命令都要以分号结束
别名不属于括号
USE my_new_test_data_base;
SELECT mytest_people.Id, mytest_people.Name, mytest_people.Age ,mytest_hobbies.`Hobby`
FROM mytest_people
INNER JOIN mytest_hobbies
ON mytest_people.H_ID = mytest_hobbies.Id
WHERE mytest_hobbies.`Hobby` LIKE 'Reading%';
如果您喜欢少打字:
SELECT p.Id
, p.Name
, p.Age
, h.hobby
FROM my_new_test_data_base.mytest_people p
JOIN my_new_test_data_base.mytest_hobbies h
ON p.H_ID = h.Id
WHERE h.Hobby LIKE 'Reading%';