2018年9月20日 星期四

網頁開發(3) 重複查詢同一資料表

對同一個資料表做重複查詢


有時候可能會對同一個資料表做重複查詢很多次
也就是需要 JOIN 兩次以上

例如( 以下範例不小心用到中文,沒試過到底可不可行 )
Table1
Table2








這時可能就需要 JOIN Table2 重複 2 次來達到完整資料
利用 AS 來達到區分 Table2 達到 JOIN 2 次的效果
    SELECT send.名稱 as sendman, recv.名稱 as recvman
    FROM Table1 as log
    LEFT JOIN Table2 AS send ON log.寄件者 = send.id
    LEFT JOIN Table2 AS recv ON log.收件者 = recv.id

Related Posts:

  • CSS vertical-align有時候 Input 的 text 或 textarea 有時候預設的對齊可能不盡理想 這時候可以用 vertical-align,這主要是用來對齊圖片的 但有時候你會想讓 textarea 對齊隔壁的物件,因為沒有此參數的話他會對齊 textarea 的底線 textarea { vertical-align:25px; // 向上修正 25px } 也有支援其他參數,但 w3schools 已有列表這邊不在… Read More
  • Strict Standards: Only variables should be passed by reference in 升級 PHP 後 會遇到錯誤回報 Strict Standards: Only variables should be passed by reference in  $SQL->bindParam(':page', getenv('REQUEST_URI')); 看到這報錯後,我變更改成以下 $temp = getenv('REQUEST_URI'); $SQL-bindParam(':page', $temp);… Read More
  • JS 日期操作 JavaScipt 日期操作 宣告 var now = new Date(); var targetDate = new Date("2018/11/24"); // IE 要注意的地方,IE date 格式為 yyyy/mm/dd var somedate = "2019-5-17"; var targetDate = new Date(somedate.replace("-","/")); * 不照IE格式會顯示 NaN-NaN-… Read More
  • PHP Function with Optional ParametersPHP Function with Optional Parameters 有 2 種方法 1. 用 NULL arguments function method($arg1 = null, $arg2 = null){ $arg1 = $arg1? $arg1: "default_value_for_arg1"; $arg2 = $arg2? $arg2: "default_value_for_arg2"; } 2. 傳 Array… Read More
  • PHP 日期加減PHP 日期加減 1. mktime() $date1 = date ("Y-m-d H:i:s" , mktime(date('H'), date('i'), date('s'), date('m'), date('d')-1, date('Y'))); $date2 = date ("Y-m-d H:i:s" , mktime(date('H'), date('i'), date('s'), date('m'), date('d'), da… Read More

0 意見:

張貼留言

Popular Posts