试图显示2个表格数据 [英] Trying to display 2 tables data
问题描述
我有2个表格
表格名称 Dist
。
名称|电话|身份证
----------------
Oakley | 555-555 | 1
Maui | 666-666 | 2
勒克斯| 777-7777 | 3
表名 Patientacct
。
名称|处方| id | orderfrom
-------------------------------
bob | 20-20 | 1 | oakley
比利| 15-20 | 2 | Oakley,Maui
kim | 20-20 | 3 |勒克斯
我正在寻找一个显示器,如$ /
Oakley
------------ --------
Bob
Billy
毛伊岛
------------------
Billy
Lux
--------------
kim
迄今为止的试验
选择*
从`dist`
加入`patientacct` ON patientacct.dist LIKE CONCAT('%',`dist`.name,'%')
GROUP BY`dist`.name
这只显示1 dist
如果我通过示例删除组:
SELECT *
FROM` dist`
JOIN'patientacct` ON patientacct.dist LIKE CONCAT('%',`dist`.name,'%')
我记录了两次,所以我需要的是两者之间的某处。我非常新加入,所以在解释时很容易。
首先,请使表格结构关系式化。在每个表中都有一个主auto_increment值,并将Dlist外键中的主键用于Patientacct。这样,一个简单的连接就可以获取你想要的记录。关于显示,你是什么意思,你不希望记录两次。由于您正在使用加入,因此您将与患者Bob和Billy一起获得Oakley的两条记录。这就是你想要的,在关系表中也可以通过简单的连接。
I have 2 tables
Table name Dist
.
NAME|Phone|ID
----------------
Oakley|555-555|1
Maui|666-666|2
lux|777-7777|3
Table name Patientacct
.
Name|prescription|id|orderfrom
-------------------------------
bob|20-20|1|oakley
billy|15-20|2|Oakley, Maui
kim|20-20|3|Lux
I'm looking for a display like
Oakley -------------------- Bob Billy
Maui ------------------ Billy
Lux -------------- kim
Trials so far
SELECT *
FROM `dist`
JOIN `patientacct` ON patientacct.dist LIKE CONCAT('%', `dist`.name ,'%')
GROUP BY `dist`.name
This showed only 1 dist
If I drop the group by example:
SELECT *
FROM `dist`
JOIN `patientacct` ON patientacct.dist LIKE CONCAT('%', `dist`.name ,'%')
I get the record twice so what I need is somewhere between the two. I'm extremely new to joins so be easy when explaining.
First of all, please make the table structure relational. Have a primary auto_increment value in each table and use the primary key from the Dlist foreign key to Patientacct. This way, a simple join would fetch the record you have wanted.
Regarding the display, what do you mean you don't want record twice. Since you are using join, you will get two records for Oakley with the patient Bob and Billy. That's what you wanted and it would be like that by a simple join too in a relational table.
这篇关于试图显示2个表格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!