Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:00:33+00:00 2026-06-14T19:00:33+00:00

I have the following structure: Album +———-+———————-+——————-+——————-+——–+ | id_album | description | name |

  • 0

I have the following structure:

Album

+----------+----------------------+-------------------+-------------------+--------+
| id_album | description          | name              | url               | status |
+----------+----------------------+-------------------+-------------------+--------+
|        1 | el primer album      | primer album      | primer-album      |      1 |
|        2 | El album del viernes | album del viernes | album-del-viernes |      1 |
|        3 | dasdas               | album 3           | album             |      1 |
+----------+----------------------+-------------------+-------------------+--------+

Photo

+----------+-------------+-----------------------------+-------+---------+
| id_photo | description | image           | album | published           |
+----------+-------------+-----------------------------+-------+---------+
|        1 |             | 1_1361894_n.jpg |     1 | 2012-05-24 13:36:36 |
|        2 |             | 1_537885_n.jpg  |     1 | 2012-05-24 13:36:39 |
|        3 |             | 17227078_n.jpg  |     1 | 2012-05-24 13:36:40 |
|        4 |             | _6891390_n.jpg  |     1 | 2012-05-24 13:36:40 |
|        5 |             | 15743568_n.jpg  |     1 | 2012-05-24 13:36:44 |
|        6 |             | -sol.jpg        |     2 | 2012-06-29 09:55:23 |
|        9 |             | fondo2.gif      |     2 | 2012-08-13 16:46:10 |
|        8 |             | barra.gif       |     1 | 2012-07-10 12:13:04 |
+----------+-------------+-----------------+-------+---------------------+

Actually, I’m selecting all albums that contains at least one photo:

SELECT a.id_album, a.name, count(p.id_photo) AS photos 
FROM album a
LEFT JOIN photo p ON a.id_album = p.album 
GROUP BY a.id_album 
HAVING photos > 0;

+----------+-------------------+--------+
| id_album | name              | photos |
+----------+-------------------+--------+
|        1 | primer album      |      6 |
|        2 | album del viernes |      2 |
+----------+-------------------+--------+

Everyting goes fine here. But now, I would like to know if is possible to include one
photo for each album into the row. For exaple:

| id_album | name | photos | id_photo | image |

Look above that I have included id_photo and image from photo table. But I don’t know how to trigger a sql to get that result. I apreciate your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:00:34+00:00Added an answer on June 14, 2026 at 7:00 pm
    SELECT a.id_album, a.name, count(p.id_photo) AS photos, p.id_photo, p.image 
    FROM album a
    LEFT JOIN photo p ON a.id_album = p.album 
    GROUP BY a.id_album 
    HAVING photos > 0;
    

    Most probably it will take first inserted album’s photo if it has any photo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following structure for check-boxes <input type=checkbox name=reg_field['first_name'] value=1 /> First Name<br />
I have following table structure in my DB ID Name -------------------------- ID_1 Name1 ID1
one more problem. I have following structure of XML: <player> <id>12</id> <name>pl_name</name> <experience> <points>147</points>
I have following table structure table domains ID | name | ________________________ 1 |
i have following structure: <td> <input name=foo size=45/> </td> And i want to dynamically
I have following table structure ID Name Parent_ID 1 abc 0 2 efg 1
one more problem. I have following structure of XML: <player> <id>12</id> <name>pl_name</name> <experience> <points>147</points>
I have following table structure: Entity --------------------- id | name Users --------------------- id |
I have following db structure in mysql. Table: Story Id Name categoryid date 1
I have following structure with example data: id season_id title 1 1 Intro 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.