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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:17:22+00:00 2026-06-07T06:17:22+00:00

All, Say I have the following Select statement in mySQL: $qry = Select filename

  • 0

All,
Say I have the following Select statement in mySQL:

$qry = "Select filename from upload where file_id='$file_id'";
$result = mysql_query($qry);
$resultset = mysql_fetch_array($result);

That query works fine but what I would also like to do is include a count of how many times that same filename appears somewhere else in that table in the same statement so I only have to run the mySQL statement once instead of getting that filename from this result and then executing another query like this one:

$qrycheck = "Select COUNT(filename) from upload where filename='$resultset[filename]'";

Is there anyway to do this check in a single mySQL statement?

Thanks!

  • 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-07T06:17:24+00:00Added an answer on June 7, 2026 at 6:17 am

    If I understand correctly, you have several instances of ‘filename’ with different file_ids (I suppose that file_id is a unique ID, so it wouldn’t make sense to count occurrences of file_id – you’d either get 1 or 0):

      file_id  filename
      1        filename1.jpg
      2        filename2.jpg
      3        filename1.jpg
      4        filename1.jpg
    

    If that’s the case, you have to JOIN upload with itself:

      SELECT uploads.filename, count(names.instance) AS instances FROM upload AS uploads
           JOIN upload AS names ON (uploads.filename = names.filename)
           WHERE uploads.file_id = '$file_id' GROUP BY uploads.filename;
    

    This will return the name in $resultset[‘filename’] and the number of instances in $resultset[‘instances’].

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

Sidebar

Related Questions

I have written the following SQL statement in MySQL : USE my_database; SELECT *
Say I have a query like the following: SELECT * FROM users WHERE username
All, Say I have the following bit of code: select: function(start, end, allDay) {
Say that I have some SELECT statement: SELECT id, name FROM people ORDER BY
say we have the following SQL: select * from ( select Id from table1
Lets say I have the following query. SELECT stringdata FROM table ORDER BY FIELDS(
I have the following query SELECT P.ID, MAX(ENTERDATE) as ENTERDATE, MAX(B.CostID) as CostID FROM
Ok, say I have a query: SELECT * FROM TABLE_AWESOME WHERE YEAR = :AMAZINGYEAR;
I have the following sql statement - it's trying to find all the zipcodes
Say I have the following markup: <div> <h3><a href=>link I want to select</a></h3> <div>

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.