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 8670375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:41:36+00:00 2026-06-12T18:41:36+00:00

This is the query that’s been getting me everything I wanted to know about

  • 0

This is the query that’s been getting me everything I wanted to know about photos in my database up until now:

SELECT
      users.facebook_id,
      users.first_name,
      users.last_name,
      photos.*,
      bookmarks.photo_id AS bookmark
FROM
      photos
JOIN users
      ON photos.author = users.facebook_id
LEFT JOIN bookmarks
    ON photos.id = bookmarks.photo_id
    AND bookmarks.facebook_id = 123456789
WHERE photos.description <> ''
ORDER BY photos.id DESC

However now, I’d like to get one more piece of information. I’d like to know how many votes have been cast on a particular photo.

Here is my votes table:

CREATE TABLE IF NOT EXISTS `votes` (
  `photo_id` int(11) NOT NULL,
  `facebook_id` bigint(20) NOT NULL COMMENT 'The user''s Facebook ID.',
  `date` varchar(10) NOT NULL COMMENT 'Date formatted as YYYY-MM-DD.',
  UNIQUE KEY `one_vote_per_day` (`photo_id`,`facebook_id`,`date`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

And here is what I tried already:

SELECT
      count(votes.photo_id) as vote_count,
      users.facebook_id,
      users.first_name,
      users.last_name,
      photos.*,
      bookmarks.photo_id AS bookmark
FROM
      photos
JOIN users
      ON photos.author = users.facebook_id
LEFT JOIN votes
    ON votes.id = photos.photo_id
LEFT JOIN bookmarks
    ON photos.id = bookmarks.photo_id
    AND bookmarks.facebook_id = 123456789
WHERE photos.description <> ''
ORDER BY photos.id DESC

Obviously I’m doing something wrong, because when I tried this, I’d never get more than a single photo in the result.

This method works fine for me when I only need information on a single photo, but this query needs to work for all photos at once…

  • 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-12T18:41:37+00:00Added an answer on June 12, 2026 at 6:41 pm

    You need group by

    SELECT
          count(votes.photo_id) as vote_count,
          users.facebook_id,
          users.first_name,
          users.last_name,
          --photos.*, you have to add all fileds you need, and add them to group by
          bookmarks.photo_id AS bookmark
    FROM
          photos
    JOIN users
          ON photos.author = users.facebook_id
    LEFT JOIN votes
        ON votes.id = photos.photo_id
    LEFT JOIN bookmarks
        ON photos.id = bookmarks.photo_id
        AND bookmarks.facebook_id = 123456789
    WHERE photos.description <> ''
    group by users.facebook_id,
             users.first_name,
             users.last_name,
             bookmarks.photo_id
    ORDER BY photos.id DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query that takes about 5 minutes to run in Oracle: select
I've got this query that works ok, select * from Materia where Cursar_Cursada=0 and
I have have this query that i want to execute. SELECT warehouse.expiry_date, pharmacy.expiry_date, drugs.active_substance,
So I have this query that works perfectly: SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories FROM
I have this query that (stripped right down) goes something like this : SELECT
I have a query that looks something like this: select xmlelement(rootNode, (case when XH.ID
So, I've got a query that looks something like this: SELECT id, DATE_FORMAT(CONVERT_TZ(callTime,'+0:00','-7:00'),'%b %d
I have this query that I'm running against mysql: SELECT video.title AS title, video.url
I have this query that runs fine: SELECT Value FROM data WHERE MetaDataID =
Consider this query that uses SELECT * and 'appends' a calculated column: SELECT *,

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.