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

  • Home
  • SEARCH
  • 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 8648015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:12:53+00:00 2026-06-12T13:12:53+00:00

Up until today, this is the query that got everything I needed to know

  • 0

Up until today, this is the query that got everything I needed to know about a photo from my database:

SELECT 
    users.facebook_id, 
    users.first_name, 
    users.last_name, 
    photos.filename, 
    photos.description, 
    photos.finalist, 
    bookmarks.photo_id AS bookmark 
FROM `photos`, `users` 
LEFT JOIN bookmarks ON bookmarks.photo_id = 123 AND bookmarks.facebook_id = 123456789 
WHERE 
    users.facebook_id = photos.author AND 
    photos.id = 123 
LIMIT 1

However, now I’d like to also find out how many votes have been cast for this 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 my attempt to modify my SQL query to fetch a vote count:

SELECT 
    users.facebook_id, 
    users.first_name, 
    users.last_name, 
    photos.filename, 
    photos.description, 
    photos.finalist, 
    bookmarks.photo_id AS bookmark,
    count(votes.*) AS vote_count
FROM `photos`, `users` 
LEFT JOIN votes ON votes.photo_id = 123  
LEFT JOIN bookmarks ON bookmarks.photo_id = 123 AND bookmarks.facebook_id = 123456789 
WHERE 
    users.facebook_id = photos.author AND 
    photos.id = 123 
LIMIT 1

The above attempt resulted in this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) AS vote_count FROM `photos`, `users` LEFT JOIN votes ON votes.photo_id = 1' at line 9
  • 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-12T13:12:55+00:00Added an answer on June 12, 2026 at 1:12 pm

    The error was caused by a syntax problem. It was the asterix. This query performs properly and as desired:

    SELECT 
        users.facebook_id, 
        users.first_name, 
        users.last_name, 
        photos.filename, 
        photos.description, 
        photos.finalist, 
        bookmarks.photo_id AS bookmark,
        count(votes.photo_id) AS vote_count
    FROM `photos`, `users` 
    LEFT JOIN votes ON votes.photo_id = 123  
    LEFT JOIN bookmarks ON bookmarks.photo_id = 123 AND bookmarks.facebook_id = 123456789 
    WHERE 
        users.facebook_id = photos.author AND 
        photos.id = 123 
    LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today, a fellow team member checked-in some code that looked like this var query
I have never really thought about this until today, but after searching the web
I need to create a select box with query data from my Database by
I want to select data between 1 week ago data until today data: SELECT
Up until earlier today, I was under the impression that if I wanted to
Only today I realized that I was missing this in my PHP scripts: mysql_set_charset('utf8');
I know just enough about SQL tuning to get myself in trouble. Today I
Until today (I have no idea what I did to cause this), if I
This is literally my first day using PHP. I've never seen it until today,
I have a user that has, up until today, been called foo.bar . Now

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.