[英]Select column names from one table based off of values in column of another table
This could be a repost;这可能是转帖; if so, link me and I will delete.
如果是这样,链接我,我会删除。
First off, I am a SQL newb.首先,我是一个 SQL 新手。 I have two tables, table_1 and table_2.
我有两个表,table_1 和 table_2。 I want to select the column names from table_1 that only correspond to values found in a column named 'foo' from table 2.
我想从 table_1 中选择仅对应于在表 2 中名为“foo”的列中找到的值的列名。
How can I got about this?我怎么知道这件事? Does this require an inner join?
这是否需要内部联接?
I have some code I can post, but it is a disaster.我有一些可以发布的代码,但这是一场灾难。
These is one type of example.这些是一种示例。
select * from table1 join table2 on table1.col1= table2.col2
we follow these above syntax.我们遵循上述这些语法。
select * from table1 join table2 on table1.col1= table2.foo
These is the how find out column_name is present in another table这些是如何找出另一个表中存在的 column_name
SELECT * FROM( SELECT letter FROM `Table_2` ) a JOIN
(SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='database_name'
AND `TABLE_NAME`='Table_1') b ON a.letter= b. COLUMN_NAME
Thank you.谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.