Jump to content

agrant

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by agrant

  1. what's your sql code look like for this? could be a number of issues... missing joins, missing indexes, etc.
  2. looks like you have a typo... try href instead of herf
  3. I agree with kickstart, union probably is the way to go. Typically the less complex the SQL the faster it will run.
  4. agrant

    structure

    First thing you have to know is what are the relations to each other? Example... a game can have zero to many different achievements or a user can only have one game... etc once you clarify that it is much easier to specify a data structure.
  5. try this instead, it's a little cleaner to figure out where your error is coming from: SELECT * FROM projects WHERE projects.ResearchID=0 AND NOT EXISTS (SELECT 1 FROM research WHERE UserID='$UserID' and research.ResearchID = projects.ResearchID) UNION SELECT * FROM projects WHERE projects.ResearchID>0 AND EXISTS (SELECT 1 FROM research WHERE UserID='$UserID' AND Completed='1' and research.ResearchID = projects.ResearchID) Also what is the difference between RecordID in projects and ResearchID in research? How are they related? It seems to me the issue is probably in the join in both of the exists/not exists subqueries with a mismatched column.
  6. The best way to explain group by is it allows you to place records into groups based on values that are stored in the designed columns. for example: select gender, count(*) as ct from people group by gender would allow you to group on the column gender, so you would expect to see something like gender --- ct M --- 50 F --- 40 50 records would have the gender value of M, 40 would have the value of F All of your columns that you have in your select need to be in your group by also... and then in your select you can use math functions such as MAX, MIN, SUM, AVG, COUNT mySQL has a good article on the usage of the group by function that you should take a look at if you haven't yet: http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html I hope all of that makes sense, Aaron
  7. Is UID your primary key? Typically on a script like this, I don't use it in an insert statement, I'll use auto increment instead example of how to implement this mySQL feature is below: CREATE TABLE `bookmarks` ( `uid` INT( 3 ) NOT NULL AUTO_INCREMENT, `name` VARCHAR( 100 ) NOT NULL , `url` VARCHAR( 250 ) NOT NULL , `description` VARCHAR( 500 ) NOT NULL , PRIMARY KEY ( `uid` ) ); More info... http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html Also are you using this script publicly? If so you might want to protect your script better again SQL injection attacks.
  8. I would write the code like this... SELECT col1, col2 FROM table WHERE filled=0 and type in ('audio','electronic','large print') select on a certain columns instead of using *, this will speed up the query. and switch the "ORs" to an "in" statement. hope that helps, Aaron
×
×
  • 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.