mysql

writting an sql query

iam having 2 tables table Items Table (this table holds all items iam having) itemId --------- Item1 Item2 Item3 Item4 Item5 table 2 users_item relation UserId || ItemId 1 || Item1 1 || Item2 userId one has stored 2 items Item1,Item2. Now i want to write a query on table1 (Items table) so that it displays all items which user1 h...

How do I query for this in Django?

| random_code | varchar(200) | YES | UNI | NULL | | MyTable.objects.filter(random_code = None) Is this correct? Will this SELECT where there is no random code set? Above is my table. ...

checkbox checked with php form post?

how do I check a checkbox? I've tried 1, On, Yes that doesn't work. putting the worked "checked" alone works but then how do I check with php after form post of the checkbox is checked? <input type="checkbox" class="inputcheckbox" id="newmsg" name=chk[newmsg2] value="1" /> ...

getting rid of filesort on WordPress MySQL query

An instance of WordPress that I manage goes down about once a day due to this monster MySQL query taking far too long: SELECT SQL_CALC_FOUND_ROWS distinct wp_posts.* FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term...

Fastest way to modify a decimal-keyed table in MySQL?

I am dealing with a MySQL table here that is keyed in a somewhat unfortunate way. Instead of using an auto increment table as a key, it uses a column of decimals to preserve order (presumably so its not too difficult to insert new rows while preserving a primary key and order). Before I go through and redo this table to something more s...

mysql Delete and Database Relationships

If I'm trying to delete multiple rows from a table and one of those rows can't be deleted because of a database relationship, what will happen? Will the rows that aren't constrained by a relationship still be deleted? Or will the entire delete fail? Thanks, Colin ...

Querying calendar events even if they do not have any for the day

Hey everyone, I am trying to figure out a way to query my mysql server so that even if a company does not have anything posted for the day and the user clicks on their logo, it still adds them to the list. That sounds a little confusing so let me try to explain it another way. Say I have 3 companies in my database: Comp1 Comp2 Comp3 ...

cakephp paginate using mysql SQL_CALC_FOUND_ROWS

I'm trying to make Cakephp paginate take advantage of the SQL_CALC_FOUND_ROWS feature in mysql to return a count of total rows while using LIMIT. Hopefully, this can eliminate the double query of paginateCount(), then paginate(). http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows I've put this in my...

inserting array into database table in single query

iam having an array of items like [item1,itmem2,item3]; i have to insert these items at a particular userId: final results look like this UserId ItemId 2 || item1 2 || item2 2 || item3 currently iam looping through the array in php code and inserting each item one by one eg foreach($items as $item) { insert into items (...

MYSQL extract day number from day

Is it possible to extertract and integer value from "Mon", Tue", "Wed" etc with an SQL statment? For example Mon = 1 Tue = 2 Wed = 3 etcv ...

How to find the nearest integer to a specified integer from a table of integers?

How to find the nearest integer upon the provided one? Say, I have the following integers in the mysql database: 405, 600, 304. The question is how to I select 600 upon providing 550 or select 304 upon providing 300 (ie, so as to find the nearest integer)? i am talking about INTEGERS, not floats. ...

How to simulate "MYSQL has gone away" error?

I'm running lots of cron job and once in a while there is a MYSQL has gone away error. I've now written some code to handle the error, but how do I simulate the error on my localhost so that the code can be tested thoroughly? ...

mySQL query : working with INTERVAL and CURDATE

Hello, i'm building a chart and i want to recieve data for each months Here's my first request which is working : SELECT s.GSP_nom AS nom, timestamp, AVG( v.vote + v.prix ) /2 AS avg FROM votes_serveur AS v INNER JOIN serveur AS s ON v.idServ = s.idServ WHERE s.valide =1 AND v.date > CURDATE() -30 GROUP BY s.GSP_nom ORDER BY avg DE...

INSERT INTO table doesn't work???

I found a tutorial from nettuts and it has a source code in it so tried implementing it in my site.. It is working now. However, it doesn't have a Registration system so I am making one. The thing is, as I have expected, my code is not working... It doesn't seem to know how to INSERT into the database. Here's the function that inserts da...

How to check whether a mysql select statement result has a value or not in php?

I have a textbox UserName and a Check Availability button next to it..... I have checked the availability by passing UserName textbox value..... But it doesn't seem to work.... Here is what i am doing? echo $UserName = $_GET['CheckUsername']; $_SESSION['state'] = $State; $queryres = "SELECT dUser_name FROM tbl_login WHERE dUser_name='$...

Validation library for PHP/mysql

Hi! Is there any lightweight validation library available for PHP that easily can check if a specific string or value is valid for a known database type - Something like this: if (is_MEDIUMINT($var)) { $this->db->insert($anothervar); } Thanks! ...

Group mysql query by 15 min intervals

I've got a monitoring system that is collecting data every n seconds (n ~=10 but varies). I'd like to aggregate the collected data by 15 minute intervals. Is there a way to corral the timestamp column into 15 minute chunks to allow for grouping to work? ...

MYSQL question - AND or OR?

Which is a better way to select ans and quest from the table? SELECT * FROM tablename WHERE option='ans' OR option='quest'"; OR SELECT * FROM tablename WHERE option='ans' AND option='quest'"; Thanks so much! ...

Turn database result into array

Hi everyone, I have just made the update/add/delete part for the "Closure table" way of organizing query hierarchical data that are shown on page 70 in this slideshare: http://www.slideshare.net/billkarwin/sql-antipatterns-strike-back My database looks like this: Table Categories: ID Name 1 Top value 2 Sub v...

How to make a SQL for this: a integral field and it's last four must be zero

ex: 1230000 is ok, 1230001 isn't ok. ...