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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:08:07+00:00 2026-06-10T01:08:07+00:00

I use a mySQL query like this one to get some of the information

  • 0

I use a mySQL query like this one to get some of the information I need about a photo:

SELECT
users.first_name,
users.last_name,
photos.filename,
photos.YEAR,
photos.description,
themes.name AS theme_name

FROM
`photos`,
`users`,
`themes`

WHERE
users.facebook_id = photos.author AND
themes.id = photos.theme AND
photos.id = 35

LIMIT 1;

I want to ‘SELECT’ one more piece of data with this query, ‘bookmarked’ which has a value of TRUE if the following query has exactly 1 row:

SELECT * FROM bookmarks WHERE photo_id = 35 and facebook_id = 19484;

Or else ‘bookmarked’ would have a value of FALSE.

Is this possible to do in a single query?

Edit – I changed Tadman’s solution slightly. Here it is, works perfectly!

SELECT
users.first_name,
users.last_name,
photos.filename,
photos.YEAR,
photos.description,
themes.name AS theme_name,
bookmarks.id AS bookmark 

FROM
`photos`,
`users`,
`themes`

LEFT JOIN bookmarks ON bookmarks.photo_id = 35 AND bookmarks.facebook_id = 19484

WHERE
users.facebook_id = photos.author AND
themes.id = photos.theme AND
photos.id = 35

LIMIT 1;

This solution doesn’t set ‘bookmark’ equal to TRUE or FALSE, but I can work with NULL vs not NULL.

  • 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-10T01:08:09+00:00Added an answer on June 10, 2026 at 1:08 am

    You could do a LEFT JOIN on this to pull the bookmark in if present. Ideally you’d have one and only one bookmark per photo per user maximum or you might have duplicated rows, one for each bookmark:

    SELECT
      ...,
      bookmarks.photo_id
    FROM photos, users, themes
    LEFT JOIN bookmarks ON bookmarks.photo_id=? AND photos.facebook_id=users.facebook_id
    WHERE
      ...
    LIMIT 1
    

    The LEFT JOIN is an optional join, that is it may or may not succeed and if it fails it will leave the associated columns as NULL. You can check that bookmarks.photo_id is defined and if so there’s a bookmark.

    Here ? represents the placeholder for the photos.id condition you’ve specified. Hopefully you’re using placeholders and proper SQL escaping for this query.

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

Sidebar

Related Questions

I am trying to use some parameters in my sql query like this; Answer_table
I would like to use an if statement in a MySQL query to SELECT
in mysql i use JOIN and one query is no problem. what about mongo?
i've got a query and i try to get some results like this: while
Is it possible use a MySQL query to perform this kind of check? If
I am trying to use this MySQL query: SET @a:=0; UPDATE tbl SET sortId=@a:=@a+1
I need some help with a MySQL query I'm working on. I have data
I have a MySQL query that results in something like this: person | some_info
I use something like this: $url_title = mysql_real_escape_string($_GET['title']); $sql = dbquery("SELECT * FROM `videos`
My question is a lot like this one . However I'm on MySQL and

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.