mysql

MySQL, Implementing a ViewCount that automatically add +1 every time

I'm MySQL, I have a table full of docs. Each row represents a doc. I'd like to have a data column for "VIEWS" that automatically adds +1 every time the row is accessed and avoid needing to write a SQL UPDATE that hits the DB after the SELECT to get the doc in the web app. Any smart clever ways to solve for this? Thanks ...

Deferring frequent updates in MySQL

I have frequent updates to a user table that simply sets the last seen time of a user, and I was wondering whether there is a simple way to defer them and group them into a single query after a short timeout (5 minutes or so). This would reduce queries on my user database quite a lot. ...

MySQL calling in Username to show instead of ID!

I have a users table, books table and authors table. An author can have many books, while a user can also have many books. (This is how my DB is currently setup). As I'm pretty new to So far my setup is like bookview.php?book_id=23 from accessing authors page, then seeing all books for the author. The single book's details are all displa...

how does MySQL implement the "group by"?

I read from the MySQL Reference Manual and find that when it can take use of index,it just do index scan,other it will create tmp tables and do things like filesort. And I also read from other article that the "Group By" result will sort by group by columns by default,if "order by null" clause added,it won't don filesort. The differenc...

Relational MySQL - fetched properties?

I'm currently using the following PHP code: // Get all subordinates $subords = array(); $supervisorID = $this->session->userdata('supervisor_id'); $result = $this->db->query(sprintf("SELECT * FROM users WHERE supervisor_id=%d AND id!=%d",$supervisorID, $supervisorID)); $user_list_query = 'user_id='.$supervisorID; ...

Most efficient way to update a MySQL Database on a Linux host with that of an ASP.Net Form on Windows host?

My kind webhost (1and1) royally asked me to go elsewhere to do something like this. I have 2 sites. One of them was developed by a .Net programmer. Now I am contracted to implement a PHP site and fetch data from the .Net site. There is an ASP.Net form that a customer fills and when they hit submit, the data gets stored in SQL Server DB...

What happens if my server loses power and I'm using the MEMORY engine?

Does the MEMORY storage engine of MySQL ever write to disk the database contents? Meaning, if I'm using the MEMORY storage engine and my database server loses power - do I lose all of my database content or is it backed up to disk? ...

issue with selecting 1 or 0 in mysql db

I am having trouble with the following SQL statement. I have had this issue before but I can't remember how I fixed the problem. I am guessing the issue with this is that MySQL sees 0 as null? Note I didn't show the first part of the Select statement as it's irrelevant. My SQL works. It's showing rows with toffline that are = to 1 as wel...

How to insert multiple check-box values inside database when one or more will be left unchecked?

I have a form that contains 5 check boxes. The user may select one or more of these check boxes. The user may select 2 and leave 3 unchecked or select 4 and leave one unchecked and so on, in that case how can I write the php/mysql code that will insert the form data into the database. With just one selection it's easy, I would do: $chec...

In Python, if I have a unix timestamp, how do I insert that into a MySQL datetime field?

I am using Python MySQLDB, and I want to insert this into DATETIME field in Mysql . How do I do that with cursor.execute? ...

Problem updating values in combobox in vb.net

I have this code, but I have a problem. When I update but do not really made any changes to the value and press the update button, the data becomes null. And it will seem that I deleted the value. I've taught of a solution, that is to add both combobox1.selectedtext and combobox1.selecteditem to the function. But it doesn't work. comb...

How do I do this query in MySQL? (datetime)

Suppose I have a datetime column in MySQL. How do I select all that have a datetime within 2500 seconds of the current datetime? SELECT ALL where current_datetime - that_datetime < 2500 ... ...

how to atomically claim a row or resource using UPDATE in mysql

i have a table of resources (lets say cars) which i want to claim atomically. I then want information about which resource I just claimed. If there's a limit of one resource per one user, i can do the following trick: UPDATE cars SET user = 'bob' WHERE user IS NULL LIMIT 1 SELECT * FROM cars WHERE user = 'bob' This way, I claim the ...

mysql query help please

i have forum_topics table and have topics_posts table now i want to select from forum_topics where have no posts from topics_posts can any one give me the one syntax like this selct from * forum_topics where have no rows in topics_posts table ...

Mysql compare using left(X,2)="AB" or X like "AB%" for speed?

Which will perform better when searching for a key with a specific prefix in MySQL? ;- i) where left(X,2)="AB" or ii) where X like "AB%" ...

spatial indexing mysql

i have to integrate spatial indexing in mysql .i got an example i almost done it.in that example INSERT INTO address VALUES('Foobar street 12', GeomFromText('POINT(2671 2500)')); inplace of 2671 and 2500 i have to insert latitude and longitude in below format 35.177 ,-77.11. How is it possibe .Please help me ...

mysql select from one server insert to another mysql server ?

I wont to do insert to one mysqll server to and get the data or do the select part of the insert into select from anther mysql server not just copy entire tables is this possible in my sql I know that in MS Sql server you can do a linked server thanks ...

Hotel Reservation system Database schema

Hi Everyone.... I am about to develop a online hotel reservation system...using php and mysql... I have some doubts about my current database schema and the business logic to get the hotels in which rooms are free between two particular dates... Does anyone know of some kind of tutorial where i can get some idea about the hotel reserva...

MySQL search for user and their roles

I am re-writing the SQL which lets a user search for any other user on our site and also shows their roles. An an example, roles can be "Writer", "Editor", "Publisher". Each role links a User to a Publication. Users can take multiple roles within multiple publications. Example table setup: "users" : user_id, firstname, lastname "pub...

How to select non-consecutive rows in MySQL?

If the primary keys of the records are 1,3,4,5,6,8 I want to select the records with pk:1,6 NOTE I don't know which ids are non-consecutive ...