본문 바로가기
PHP

sql

by 영감은어디에 2024. 10. 11.

가져오기, join

SELECT article.id, article.title, 
       category.name,
       image.file, image.alt

  FROM article 
  JOIN category   ON article.category_id = category.id
  LEFT JOIN image ON article.image_id    = image.id

 WHERE article.category_id = 3 
   AND article.published   = 1
 ORDER BY article.id DESC;

 


결합하기, AS (앨리어스)

SELECT CONCAT(forename, ' ', surname) AS author 
  FROM member;

null 대체 

SELECT COALESCE(picture, forename, 'friend') AS profile
  FROM member;

추가

INSERT INTO image (file, alt)
VALUES ('bicycle.jpg', 'Photo of bicycle'),
       ('ghost.png',   'Illustration of ghost'),
       ('stamp.jpg',   'Polite Society stamp');

업데이트

UPDATE category 
   SET navigation = 0
 WHERE navigation = 1;

삭제 

DELETE FROM category 
 WHERE id = 5;

'PHP' 카테고리의 다른 글

Updating data - article  (0) 2024.10.12
Updating data - category  (0) 2024.10.12
getting data  (0) 2024.10.11
date  (0) 2024.10.10
image file  (0) 2024.10.10
form  (0) 2024.10.10
내장함수, number, update  (0) 2024.10.10
object  (0) 2024.10.09