mysql

Comparing 2 mysql tables and updating only records that have changed

I have the following. Two mysql tables. I want to copy info that has changed from table a to b. For example if row 1 column 2 has changed in table a I want to only update that column in table b. Table b is not the same as a but has same columns that also exist in a. The other solution I have is to just clear table b and replace it with ...

MySQL: Copy a field to another table

I have a table posts that could look like this: id | title | body | created | .. ------------------------------------------- I would like to use the boolean search feature that is offered by a MyISAM Table, but the posts table is InnoDB. So I created another table 'post_contents' that looks like this: post_id | body ----...

detecting locked tables mysql (locked by LOCK TABLE)

Hi guys, I would like to know whether is there an option to detect locked tables in mysql or no. I mean locked by LOCK TABLE table WRITE/READ command ? cheers, Marcin ...

Can you contrive a simple example in MySQL where clustered index is the solution, instead of normal index?

I don't see the point of clustered index, when will we benefit? ...

Does compound index have direction in MySQL?

When will the below be necessary: create index i_t_a_b on t(a,b); create index i_t_b_a on t(b,a); ...

In mySQL, how do I return a list of grouped items limited to a certain number of groups + unique items.

Okay, so this one may be difficult but I will do my best to explain. Bear with me... I have a table with multiple columns as follows. ITEM_ID - GROUP_ID 1 - null 2 - null 3 - null 4 - 3 5 - 3 6 - 3 7 - 21 8 - 6 9 - ...

Testing + production server and syncing MySQL data

I have a web application running on LAMP with a testing server and a production server. Is there a standard practice for keeping the data on the testing server in sync with the production server? The data on the testing server gets out of date pretty quick and I feel like there must be an easier way than just dumping the production serve...

Use terms from text file in SQL WHERE ... IN clause

I'm running SQL query for MySQL server with ... where name in ("term1","term2","term3") I would like to get the list of terms from a text file with one term per line. How can I do this? What about if this list of terms will get large? 10K, for example. Will this be efficient or I should use another approach? May be temporary table an...

Is it possible to combine these 3 mySQL queries?

I know the $downloadfile - and I want the $user_id. By trial and error I found that this does what I want. But it's 3 separate queries and 3 while loops. I have a feeling there is a better way. And yes, I only have a very little idea about what I'm doing :) $result = pod_query("SELECT ID FROM wp_posts WHERE guid LIKE '%/$downloadfile'")...

How to join mysql tables

I've an old table like this: user> id | name | address | comments And now I've to create an "alias" table to allow some users to have an alias name for some reasons. I've created a new table 'user_alias' like this: user_alias> name | user But now I have a problem due my poor SQL level... How to join both tables to generate somethin...

Splitting tables by field to optimize MySQL?

Do splitting fields into multiple tables ever yield faster queries? Consider the following two scenarios: Table1 ----------- int PersonID text Value1 float Value2 or Table1 ----------- int PersonID text Value1 Table2 ----------- int PersonID float Value2 If Value1 and Value2 are always being displayed together, I imagine the fir...

Sql query - selecting top 5 rows and further selecting rows only if User is present

Hello, I kind of stuck on how to implement this query - this is pretty similar to the query I posted earlier but I'm not able to crack it. I have a shopping table where everytime a user buys anything, a record is inserted. Some of the fields are * shopping_id (primary key) * store_id * user_id Now what I need is to pull only the li...

Building counters from paginated search results...?

I'm creating eBay style search panes that allow users to narrow their results set by certain criteria. For example: Tags Literature (8) Fiction (4) English (4) American (3) Non-fiction (2) The number of results which have that property is in brackets. Initially, I built the counters by putting this code in my display ...

convert date string to mysql datetime field

I have a bunch of records with dates formatted as a string such as '04/17/2009' I want to convert them to a mysql datetime field I plan to use a foreach loop to read the old date value and insert the newly formatted value into a new field in each record what would be the best way to convert that string...I thought php might have a way...

Mysql filling in missing dates

I have the following query SELECT * FROM attend RIGHT OUTER JOIN noattend ON attend.date = noattend.date2 WHERE attend.date BETWEEN '2010-02-01' AND '2010-04-01' AND attend.customerid =1 ORDER BY date DESC LIMIT 0 , 30 Attend is the table with customerid noattend is the table with a row for each date (date2) I followed the advice i...

Cleaner way of manually updating multiple rows

I wanted to see if there is a cleaner and more effective way of writing the SQL statement below. (MySQL) UPDATE login SET is_admin=1 WHERE memberid = 1 OR memberid = 6 OR memberid = 10 OR memberid = 12 OR memberid = 7 OR memberid = 3; Simply want a nicer way of solving it. Optimize :) ...

is it a good practice to use mysql_free_result($result)??

Hi, I am aware of that All associated result memory is automatically freed at the end of the script's execution. But would you recommend using it, if I am using a quite of lot of somewhat similar actions as below? $sql = "select * from products"; $result = mysql_query($sql); if($result && mysql_num_rows($result) > 0) { while($data =...

How to make sql query dynamic?

Hello, I am using this pagination class and was looking for a way to make the sql query more dynamic instead of having it hardcoded. I have a 3 <li> elements that I want to be filter buttons, meaning when a user clicks on one of these elements I want It to send the id so I can use it in a sql query. So for the $sql = "select * from ex...

MySQL - Calculate the net time difference between two date-times while excluding breaks?

In a MySQL query I am using the timediff/time_to_sec functions to calculate the total minutes between two date-times. For example: 2010-03-23 10:00:00 - 2010-03-23 08:00:00 = 120 minutes What I would like to do is exclude any breaks that occur during the selected time range. For example: 2010-03-23 10:00:00 - 2010-03-23 08:00:00 - ...

NHibernate mapping in Asp.Net using MySql

Hi, I'm new to NHibernate. Actually I'm trying to save the values ffrom two text boxes into MySql Database in asp.Net page. I that I got "Resource not found: WebApplication1.Sample.hbm.xml" error. But I can't fix this error. Can anyone help me to fix this one? ...