LoginSignup
0
0
記事投稿キャンペーン 「AI、機械学習」

【SQL】concatでURLのカラムを作成する。

Last updated at Posted at 2023-11-18

問題の背景

Webサイト上の商品名と商品のURLをまとめたビューを作る必要があり、各商品のURLはURLの末尾がそれぞれの商品IDとなっている。

→URLのテンプレートと商品IDを使って、すべての商品のURLを作成してカラムを作りたい。

concat()の使い方

concatは文字列と文字列を結合することができる。
CONCAT(文字列1, 文字列2)
文字列の部分に特定のテーブルのカラムを選択することで、特定の文字列とカラムを合わせた新しい文字列を作ることができる。

SQL

CONCAT("https://imazon.com/products/", product.id) AS product_url

以下のようなテーブルが作成される。

スクリーンショット 2023-11-18 19.46.59.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0