---
title: "如何插入多条记录的sql语句"
author: "duyunfengsolo"
date: "2009-12-08T15:37:30Z"
tags: []
categories: ["数据库"]
slug: "sql"
draft: false
lastmod: "2009-12-08T15:37:30Z"
id: 544136
url: "https://solodu.iteye.com/blog/544136"
---

```
1. 首先主键id是自增长的。

2. insert into scene_gallery(scene_id,gallery_id) select 148,g.id from gallery g where (g.path like '%Prinzzess%' and g.path like '%960x640' ) or (g.path like '%Prinzzess%' and  g.path like '%480x320')

解释：
(1) insert into scene_gallery(scene_id,gallery_id) values(1,1);这种是插入单条语句的写法。
(2) 插入多条语句时不用values 。
    select 148,g.id from gallery g where (g.path like '%Prinzzess%' and g.path like '%960x640' ) or (g.path like '%Prinzzess%' and  g.path like '%480x320')
这个单独成句可以查询出所有符合条件的gallery的id，然后再select 148,g.id 这样就可以查询出两列出来了，这样就可以插入到数据库表的scene_gallery中了。
```