如何在MySQL中同时显示两个表格而不进行连接操作。

huangapple go评论46阅读模式
英文:

How to Display two table in mysql together without joining

问题

你好,有人能告诉我如果我想显示具有相同行名称的两个表,我应该学习什么?很难解释,但我可以举个例子。

我有两张表,tbwinner和tbloser。
它们有相同的行(ID,日期,姓名,积分,结果)。

我想显示所有具有特定日期的tbwinner行,并按ID升序显示tbloser。

例子:

ID, 日期, 姓名, 积分, 结果
1, 12-12-2001, 测试员1, 50, 输(来自tbloser表)
2, 12-12-2001, 测试员2, 90, 赢(来自tbwinner表)
3, 12-12-2001, 测试员3, 87, 赢(来自tbwinner表)
1, 12-12-2001, 测试员4, 40, 输(来自tbloser表)

我尝试过:

SELECT *
FROM tbwinner
INNER JOIN tbloser ON tbwinner.日期 = tbloser.PV日期 WHERE tblpvdeleted.PV日期 ='2023-01-09' OR tblpv.PV日期 = '2023-01-09';

结果只显示了tbwinner表,tbloser表没有显示。

结果部分正确,因为只有tbwinner表显示了,而tbloser表没有显示。

希望有人能理解,谢谢。

英文:

Hello anyone can tell me what should I study about joining a table if I want to display two table with same row name? its hard to explain but I can give an example

I have 2 tables name tbwinner and tbloser.
they have the same rows ( ID, Date, Name, Points, Result )

what I want is to display all tbwinner rows with specific Date together with the tbloser asc by ID.

example

ID, Date, Name, Points, Result
1, 12-12-2001, Tester1, 50, Lose (this is from table tbloser)
2, 12-12-2001, Tester2, 90, Win  (this is from table tbwinner)
3, 12-12-2001, Tester3, 87, Win  (this is from table tbwinner)
1, 12-12-2001, Tester4, 40, Lose (this is from table tbloser)

I tried

SELECT *
FROM tbwinner
INNER JOIN tbloser ON tbwinner.Date = tbloser.PVDate where tblpvdeleted.PVDate ='2023-01-09' OR tblpv.PVDate = '2023-01-09'

The result show is for tbwinner only and the loser table is not displaying.

the result is half good, because only the tbwinner is display while the tbloser is not

I hope someone can understand this thanks

答案1

得分: 1

使用 UNION

您可以根据您的需要使用以下任一方法:

**使用 UNION**

SELECT ...
FROM (
    SELECT f1, f2, f3 FROM table1
    UNION
    SELECT f1, f2, f3 FROM table2
)
WHERE <您的条件>;

多选(简单)

SELECT * FROM table1, table2
英文:

You can use either approach as per your need:

Using UNION

SELECT ...
FROM (
    SELECT f1,f2,f3 FROM table1
    UNION
    SELECT f1,f2,f3 FROM table2
)
WHERE &lt; your condition &gt;

Multi-select (easy)

SELECT * from table1,table2 

huangapple
  • 本文由 发表于 2023年1月9日 17:30:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055309.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定