Jump to content

artacus

Members
  • Posts

    737
  • Joined

  • Last visited

    Never

Posts posted by artacus

  1. No union. I'm not sure if you've got a full text index or not. Use match() against() if you do.

     
    SELECT d.*
    FROM documents AS d
    LEFT JOIN vartitles AS v ON d.id = v.doc_id
    WHERE d.title LIKE '%search%' OR v.vartitle LIKE '%search%'
    GROUP BY d.id

  2. You'll have to left join this table back on itself so you can eliminate the ones w/ future close dates

    SELECT COUNT(*) 
    FROM status AS s1
    LEFT JOIN status AS s2 ON s1.ApplNo = s2.ApplNo AND s2.Status = 'CLOS'
    WHERE s1.Status='PEND' AND s1.StatusDate BETWEEN '20070203' AND '20070306' 
    AND s2.ApplNo IS NULL

  3. Is there a way just to write Recordset once and then write the query

     

     

    //You could either just write it as one big string
    $query = "SELECT ...
                  FROM ...
                  WHERE...
                  GROUP BY... "
    
    //or if  you want to split it up just use "." to join the strings
    $query = "SELECT... " .
                  "FROM ..." .
                  "WHERE ... " . 
                  "GROUP BY... ";
    

     

    I prefer the 1st one because it contains new line chars so if something is broken, you can echo it out enclosed in pre tags and have a much more readable query.

  4. I've got an idea that will work, but I don't think its very elegant. Maybe someone will post a better solution, but until then...

     

    SELECT items.*
    FROM items
    JOIN (
        SELECT item_id, GROUP_CONCAT(t_id) AS tids
        FROM tag 
        GROUP BY item_id
    ) AS sub ON items.id = sub.item_id
    WHERE FIND_IN_SET(12, sub.tids) AND FIND_IN_SET(42, sub.tids)
    

  5. Well if you don't know what you're looking for...

    And did fenway slap you yet for using date as a field name? *slap*

     

    Now that that is out of the way...

    If you want to get products viewed today use:

    WHERE DATE(VIEWED_PRODUCTS.DATE) = CURDATE()

  6. Well, you can do 10,000 inserts per second for the next 2.9 million years and you'll still have a few pk's left.

     

    10,000 inserts per month for a total of 1.2 million records is something your system can easily handle. You'll want to have good indexes set up for searching and joining for this many records. I have no idea how big your table is, if you've got text or blob fields you could run out of disk space.

  7. what an ugly way to write your query (in php)...

     

    Its harder for you to write the query because its not normalized. If you are not too far into this project, you may want to work thru a couple tutorials or even a book on db design.

     

    Otherwise, its not a great design, but it is workable.

     

    What I would do is get the match and the rating change in a sub query (so it doesn't matter if its player1 or 2), er you don't have a match_id, you should have a pk on your match table

     

    SELECT 
    FROM (
         SELECT m.id, m.meetID
         IF(m.player1ID = '$playerID', m.rating1Before, m.rating2Before) AS ratingBefore,
         IF(m.player1ID = '$playerID', m.rating1Change, m.rating2Change) AS ratingChange,
         IF(m.player1ID = '$playerID', m.player2ID, m.player1ID) AS opponentID
         FROM matches AS m
         WHERE m.player1ID = '$playerID' OR m.player2ID = '$playerID'
    ) AS sub
    JOIN teams and such...
    

     

  8. Then you'll need to use innoDB tables because myISAM does not support fk relationships. I'm not really sure what you mean by "reference."

    You can join them in a query w/o having fk's defined. phpMyAdmin also stores relationship information in a separate database if you have that set up right. But like I said, I'm not really sure what you are asking.

×
×
  • 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.