简体   繁体   中英

How do I write a query that bridges two tables?

I have two tables, two differently name columns in these tables match up.

Table A:
a
b
c
d
e

Table B:
f
g
h

I need to display a grid view of e, g and h, Joining the tables together based on the f and b matching up. I know how to fill a grid view based on a query, its just the query itself I'm after.

Since all of your columns are uniquely named, and you are joining two different tables, no aliasing is necessary, and you don't need to fully qualify the column names.

The SQL term you are looking for is a JOIN. In this case, it sounds like you want an inner join (there are many ways to write them).

SELECT 
    e,g,h
FROM 
    TableA 
    INNER JOIN TableB 
        ON b = f

您在问题中使用了恰如其分的词:“ 根据匹配的f和b将表连接在一起 ”。

SELECT e,g,h FROM `Table A` JOIN `Table B` ON f=b

I think it might be:

SELECT e,g,h FROM Table A, Table B WHERE Table A.b == Table B.f

That's the JOIN I would use. It may need tweaked depending on what your variables are.

Sorry, this works for SQL not MYSQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM