アプリ関連ニュース

SQL Joins

Today I would like to talk about MySQL joins along with some practical example queries.

Inner Join

2テーブルの中で同じレコードだけ出る。
(return only matching records from both tables)

Left Join

left テーブルは全レコードが出る、right テーブルのは同じレコードだけ
(return all records from the left table, and only the matched records from the right table)

Right Join

right テーブルは全レコードが出る、leftテーブルのは同じレコードだけ
(return all records from the right table, and only the matched records from the left table)

Full Outer Join

同じレコードが有る時全部レコードが出る。
(return all records from both tables if there is match record between them)

Inner Join Query Example

SELECT column(s)
FROM tb1
INNER JOIN tb2
ON tb1.column = tb2.column;

Left Join Query Example

SELECT column(s)
FROM tb1
LEFT JOIN tb2
ON tb1.column = tb2.column;

Right Join Query Example

SELECT column(s)
FROM tb1
RIGHT JOIN tb2
ON tb1.column = tb2.column;

Full Outer Join Query Example

mysql doesn’t support full join syntax directly so we can use this as an alternative.
(full join = left + right join)

SELECT column(s)
FROM tb1
LEFT JOIN tb2 ON tb1.column = tb2.column;
LEFT JOIN tb3 ON tb1.column = tb3.column;
UNION
SELECT column(s)
FROM tb1
SELECT column(s)
FROM tb1
RIGHT JOIN tb2 ON tb1.column = tb2.column;
RIGHT JOIN tb3 ON tb1.column = tb3.column;



[HTC VIVE + Unity] レーザーポインターの実装方法 (1)

HTC VIVE用VRアプリ開発でUnityを使用してレーザーポインターを実装する方法を紹介します。

続きを読む

Calculation of time elapsed in PHP

Today I would like to write some code about calculating time elapsed in PHP. Especially if we want to know the elapsed time of inserted records (seconds, minutes, hours , days etc).

For example – Posted 1 週前、3 時間前、50 分間前、30秒間前。

Here is our function to calculate the time eclipse

<?php

function time_elapsed($datetime) {
    $now = new DateTime;
    $ago = new DateTime($datetime);
    //getting the time differences.
    $diff = $now->diff($ago);

    $diff->w = floor($diff->d / 7); //week
    $diff->d -= $diff->w * 7; //day

    //string arrays of formats
    $string = array(
        'y' => '年',
        'm' => '月',
        'w' => '週',
        'd' => '日',
        'h' => '時間',
        'i' => '分',
        's' => '秒',
    );

    //mapping the time difference and format
    foreach ($string as $k => &$v) {
        if ($diff->$k) {
            $v = $diff->$k . ' ' . $v; 
        } else {
            unset($string[$k]);
        }
    }

    //only getting the first array key and value
    $string = array_slice($string, 0, 1);
    return $string ? implode(', ', $string) . '前' : 'ちょうど今';
}

I have included the comments in code so that you can be able to understand it. Let’s call our function to test.

echo time_elapsed("2020-12-06 11:24:25"); //output 1 月前
echo time_elapsed(date("Y-m-d H:i:s")); //output ちょうど今

PS. we have to care about our server timezone when we are dealing with Datetime functions

By Yuuma



[Unity] Visual Studioの入力補完が機能しない場合の対処方法

本日はUnityを使用していて、連携するVisual Studioでコーディングをおこなう際にVisual Studioの入力補完が機能しない場合の対処方法を紹介します。

続きを読む

CES2021で発表された平面と曲面を切り替え可能な有機ELディスプレイ

自己発光する有機ELはバックライトが不要で、
シート状でも使用することができます。

最近ではスマートフォン、タブレットや、
テレビ等の身近なところで利用が広がっていますね、

続きを読む

アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム