在 MySql 中搜索多个 table 时,有什么方法可以知道哪个 table 包含特定条目
Is there any way to know which table contain the specific entry while searching multiple tables in MySql
我在数据库中有多个 table。我正在搜索所有 table 以查找特定条目。搜索结果returns正确。但是我怎么知道哪个 table 包含 MySql 中的特定 data/entry?在搜索多个 table 时,有没有办法 return/know 包含特定条目的 table 名称?
Dim statusQuery As String = $"SELECT * FROM management.hostelA,management.hostelB,management.hostelC,management.hostelD where hostelA.occupant1='{stu_name.Text}' or hostelA.occupant2='{stu_name.Text}' or hostelB.occupant1='{stu_name.Text}' or hostelB.occupant2='{stu_name.Text}' or hostelC.occupant1='{stu_name.Text}' or hostelC.occupant2='{stu_name.Text}' or hostelD.occupant1='{stu_name.Text}' or hostelD.occupant2='{stu_name.Text}'"
cmd = New MySqlCommand(statusQuery, con)
Dim sdr As MySqlDataReader
sdr = cmd.ExecuteReader
While sdr.Read
statusflag = statusflag + 1
End While
我想知道哪个 table 包含 stu_name.text
您最好单独查询每个 table,即一次查询一个 table。然后你会很容易地看到这个名字是在哪个table中找到的。
尽管来自@Uueerdo 的评论,你并没有做一堆 UNION
操作,你正在做一堆 JOIN
操作。这意味着您的查询正在执行四个 table 的巨大 Cartesian product。换句话说,所有四个 table 的每一行都与所有其他 table 的每一行匹配。我确定这不是您想要的。
在你尝试做这样的事情之前,你需要学习 SQL。
到那时,您应该一次查询 table 个。
我在数据库中有多个 table。我正在搜索所有 table 以查找特定条目。搜索结果returns正确。但是我怎么知道哪个 table 包含 MySql 中的特定 data/entry?在搜索多个 table 时,有没有办法 return/know 包含特定条目的 table 名称?
Dim statusQuery As String = $"SELECT * FROM management.hostelA,management.hostelB,management.hostelC,management.hostelD where hostelA.occupant1='{stu_name.Text}' or hostelA.occupant2='{stu_name.Text}' or hostelB.occupant1='{stu_name.Text}' or hostelB.occupant2='{stu_name.Text}' or hostelC.occupant1='{stu_name.Text}' or hostelC.occupant2='{stu_name.Text}' or hostelD.occupant1='{stu_name.Text}' or hostelD.occupant2='{stu_name.Text}'"
cmd = New MySqlCommand(statusQuery, con)
Dim sdr As MySqlDataReader
sdr = cmd.ExecuteReader
While sdr.Read
statusflag = statusflag + 1
End While
我想知道哪个 table 包含 stu_name.text
您最好单独查询每个 table,即一次查询一个 table。然后你会很容易地看到这个名字是在哪个table中找到的。
尽管来自@Uueerdo 的评论,你并没有做一堆 UNION
操作,你正在做一堆 JOIN
操作。这意味着您的查询正在执行四个 table 的巨大 Cartesian product。换句话说,所有四个 table 的每一行都与所有其他 table 的每一行匹配。我确定这不是您想要的。
在你尝试做这样的事情之前,你需要学习 SQL。
到那时,您应该一次查询 table 个。