0

How to select the every first character from mysql database with different gallery name, i have that database - how to select the first image with galery name(column "gallery") img and the first image with gallery name img2?

http://prikachi.com/images/989/7212989B.png

enter image description here

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

2 Answers2

0

You can use-

LIMIT 0,1

with your query, so that only 1 item (first item) is fetched.

For eg:

SELECT * FROM {table} WHERE gallery="img2" LIMIT 1
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
0

If you want the first image in each gallery, then you have to GROUP BY the gallery column, and select the column you want, like:

SELECT gallery, min(id) from {table} GROUP BY gallery;

This will give you the output:

| gallery  |  id  |
+----------+------+
| img      |   1  |
| img2     |   2  |
msound
  • 445
  • 3
  • 7