[英]Selecting the values of columns in a sql subquery
我想顯示數據庫中所有表的實際header_titles(每個表中的一行)
我目前的查詢
select column_name, table_name from information_schema.columns
where column_name in (
select column_name from information_schema.tables
where table_schema='site'
) and
column_name='header_title';
此刻查詢返回“ header_titles” 12次(數據庫中帶有該字段的表的數量,顯然還有表名。我不確定如何獲取每個header_titles的值
一個非常簡單的例子
$query = "SELECT table_name FROM information_schema.tables AS tbl
WHERE EXISTS(SELECT 1 FROM information_schema.columns AS col
WHERE tbl.table_name = col.table_name AND column_name = 'header_title')";
$result = mysqli_query($conn, $query) or trigger_error(mysqli_error($conn), E_USER_ERROR);
while($row = mysqli_fetch_row($result))
{
$q = 'SELECT header_title FROM '.$row[0];
$r = mysqli_query($conn, $q) or trigger_error(mysqli_error($conn), E_USER_ERROR);
$index = 0;
while($data = mysqli_fetch_row($r))
{
$index++;
echo "Table = ".$row[0].", row = ".$index.", HEADER_TITLE = ".$data[0].PHP_EOL;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.