I would like to make a SELECT query that depends on two other tables
我想做一个依赖于其他两个表的SELECT查询
table 1: tbcategories
表1:tbcategories
id name
-- ----
1 category1
2 category2
3 category3
table 2: tbgroups
表2:tbgroups
id category name
-- -------- ----
1 1 group1
2 1 group2
3 2 group3
table 3: tbchilds
表3:tbchilds
id group name
-- ----- ----
1 group1 child1
2 group1 child2
3 group2 child3
4 group2 child4
5 group3 child5
What I need - The query syntax which gives me all the childs (tbchilds) that their "group" is on specific category. For example: give me all the childs that "under" category1 = the output will be:
我需要的 - 查询语法,它给了我所有的孩子(tbchilds)他们的“组”在特定类别。例如:给我所有的孩子“在”category1 =输出将是:
child1
child2
child3
child4
10X
5 个解决方案
#1
0
Best example for PHP MySQL joins
PHP MySQL连接的最佳示例
Try
SELECT ch.name FROM tbchilds ch
JOIN tbgroups gr ON ch.group=gr.name
JOIN tbcategories cat ON cat.id=gr.category
WHERE cat.name='category1';
#2
1
SELECT *
FROM tbcategories a
INNER JOIN
tbgroups b
ON
a.id = b.category
JOIN
tbchilds t3
ON
t2.name = t3.group
WHERE
t1.name ='category1'
#3
0
this untested query should get you the expected result:
这个未经测试的查询应该会得到预期的结果:
select t3.name from tbcategories t1 join tbgroups t2 on t1.id = t2.category join tbchilds t3 on t2.name=t3.`group` where t1.name ='category1'
#4
0
Use Following Query -
使用以下查询 -
SELECT CH.name FROM tbgroups AS G
INNER JOIN tbchilds AS CH ON CH.group = G.id
INNER JOIN tbcategories AS C ON C.id = G.category
WHERE C.id = <CategoryID>;
#5
0
You can try somthing like this:
你可以尝试这样的事情:
SELECT C.name
FROM tbcategories A
INNER JOIN tbgroups B
ON A.id = B.category
INNER JOIN tbchilds C
ON B.name = C.group
WHERE A.name = 'CATEGORY1';
Hope this is helpful to you.
希望这对你有所帮助。
#1
0
Best example for PHP MySQL joins
PHP MySQL连接的最佳示例
Try
SELECT ch.name FROM tbchilds ch
JOIN tbgroups gr ON ch.group=gr.name
JOIN tbcategories cat ON cat.id=gr.category
WHERE cat.name='category1';
#2
1
SELECT *
FROM tbcategories a
INNER JOIN
tbgroups b
ON
a.id = b.category
JOIN
tbchilds t3
ON
t2.name = t3.group
WHERE
t1.name ='category1'
#3
0
this untested query should get you the expected result:
这个未经测试的查询应该会得到预期的结果:
select t3.name from tbcategories t1 join tbgroups t2 on t1.id = t2.category join tbchilds t3 on t2.name=t3.`group` where t1.name ='category1'
#4
0
Use Following Query -
使用以下查询 -
SELECT CH.name FROM tbgroups AS G
INNER JOIN tbchilds AS CH ON CH.group = G.id
INNER JOIN tbcategories AS C ON C.id = G.category
WHERE C.id = <CategoryID>;
#5
0
You can try somthing like this:
你可以尝试这样的事情:
SELECT C.name
FROM tbcategories A
INNER JOIN tbgroups B
ON A.id = B.category
INNER JOIN tbchilds C
ON B.name = C.group
WHERE A.name = 'CATEGORY1';
Hope this is helpful to you.
希望这对你有所帮助。