简体   繁体   English

如何从另一个表中获得与另一个表中的名称或ID匹配的相同名称或ID

[英]How to get same name or id from another table with matching name or id in another table

I am using c# and mysql database 我正在使用c#和mysql数据库
I have 2 tables 我有2张桌子
1st is for info 第一是信息

(Int primary key)          (varchar)             (int)
    Id                       name                 year
   2015                      user1                 1
   2016                      user2                 2

2nd is for accounts 第二个是帐户

(Int primary key)        (varchar)               (varchar)
Id (username)              name                   password
2015                       user1                    123
2016                       user2                    123

I want to make query that if I would go to make an account with the same id(username) or name after the login then it will show it in datagrid, but I don't know what query I should use. 我想查询一下,如果我要在登录后创建一个具有相同id(username)或名称的帐户,那么它将在datagrid中显示它,但是我不知道我应该使用什么查询。

That means I want to get a result like this for every account which has the same id or name and not show all the data after the login 这意味着我想为每个具有相同ID或名称的帐户获得这样的结果,并且在登录后不显示所有数据

3rd table showed in datagrid datagrid中显示的第三张表

Id                                  name                 year
2015                                user1                  1

When a user does « login » then its id is available to the application. 当用户进行“登录”时,其ID可用于应用程序。 Just pass this id to a simple SELECT query (seems like you don't even need a JOIN) : 只需将此id传递给简单的SELECT查询(似乎您甚至不需要JOIN):

SELECT
    tblstudent.StudentID, 
    tblstudent.Name, 
    tblstudent.YearLevel 
FROM
    tblstudent 
WHERE tblstudent.StudentID = ?

You want to replace the « ? 您要更换«吗? » with the id of the student that just logged in. »和刚刚登录的学生的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体框架 - 根据另一个表中的 ID 获取实体名称 - Entity Framework - Get name of entity based on ID from another table 如何使用linq从另一个表中订购具有匹配ID的数据? - How to order data with matching ID from another table using linq? 如何从另一个表中获取基于ID的一个表数据 - How to get One Table data on the basis of ID from another table 如何在另一个表的视图中显示类别名称而不是类别ID? - How to show Category Name instead of Category ID in View from another table? 如何用另一个表/列表中的匹配值替换id? - How to replace id with matching value in another table/list? 使用linq从表1中获取其名称在表2中的名称 - Get name from table 1 whose id in table 2 using linq 合并2个具有相同ID或名称的动态表数据 - Merge 2 dynamic table data with same ID or name 如何在LINQ中基于给定ID通过另一个表名查看模型字段? - How View Model field by another table name based on given ID in LINQ? 如何将一张表的id设置到另一张表 - How can i set the id from one table to another table 从SQL插入查询中获取新记录主键ID以将相同值插入另一个表中? - Get the new record primary key ID from SQL insert query to insert same value into another table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM