Jump to content

Sepph

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Sepph's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I've been going through the Oracle Database Programmer Course and it does mention subqueries must be on the right side of a comparison. Maybe this rule applies to Oracle only?
  2. Hi, is it corrent to write (<subquery here>) <op> <constant>? I.e. WHERE (SELECT COUNT(*) FROM Employees) > 10 <- WRONG? I have read this is wrong and only <constant> <op> (<subquery>) works I.e. 10 < WHERE (SELECT COUNT(*) FROM Employees) Is there a difference between MSSQL and MySQL related to this?
  3. Still haven't managed to get this to work. Any help as to how to link everything together would be appreciated!
  4. Bumped into another problem... Trying to select users that have a minimum of X photos with a minimum of Y votes. This is what my query looks like: $query = sprintf("SELECT firstname, lastname FROM users, photos WHERE (SELECT COUNT(*) AS photoCount FROM photos WHERE (SELECT COUNT(*) AS votesCount FROM votes, photos WHERE votes.photo_id=photos.id ) >= '%s' ) >= '%s' AND users.id = photos.user_id", mysql_real_escape_string($votes), mysql_real_escape_string($photos) ); Not getting the right results...
  5. Thanks again, they both work great
  6. Alright, another question if I may... I want to count the photos with no votes. Problem is the votes table contains votes already given, so it doesn't contain photo id's for photos with no votes, which means I can't count them. I've just been using a separate table column with the vote cache, but is there a workaround inside the query? The votes table contains: id, photo_id, ip, created_at.
  7. BTW is it possible to do this with JOINs?
  8. They work like a charm, thanks a lot mate, never thought I actually don't even need the users or photos tables.
  9. Hi, I need some help understanding subqueries. I've tried reading general documentation but it's not really helping. The best way I think I'll understand is by seeing the code for what I need a subquery. So, I want to display the number of users that have posted more than X photos in the past X days. The related tables with their relevant fields for this are users (id) and photos (id, user_id, created_at etc). Another subquery I'd need is to count all photos with more than X tags. tags and users are linked by a taggings table. The related tables of the db for this subquery would be users (id), tags (id), taggings (photo_id, tag_id). I'm used to doing queries with the sprintf function, using mysql_real_escape_string, so I'd best understand if these were used in the explanation. Any help would be appreciated, thanks in advance!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.