mysql

How to write this challenging SQL (MySQL) command?

This is the scenario: I am developing a website which is similar to stackoverflow.com. After an asker/seeker posts his question, other users can post their answers to the question. A user can post more than one answer to the same question, but usually only the latest answer will be displayed. User can give comments on an answer, if comme...

Re-assign host access permission to MySQL user

Hello, I have several thousand MySQL users all set to allow access from a specific host. The problem is that now I'm going to have two machines (more in the future) which will need to use the same account to access each of their databases. I'd like to a quick and easy (as automated as possible) way to run through and modify the host por...

MySQL UNION print every other

How can I make a sql query like the following: (SELECT `name` FROM table1) UNION (SELECT `name` FROM table2) return each other. Ie. name1 from table1, name1 from table2, name2 from table1, name2 from table2 and so on? Edit: Table1 name Hello world Table2 name guten tag The output wanted: Hello guten world tag and this should...

problem is select in mysql

hi my friends now i have table call files its have time has this stamp 1260606325 now i tring to get the files which added in the last 7 day SELECT * FROM `files` WHERE time > SUBDATE(NOW(),604800) its return zero how i can do that ...

How to get the top N values of each column in MySql

I have a table with 50 columns and 1000s of rows. I want to output the top 5 records for each column. To get 1 record I do: SELECT MAX(column1), MAX(column2), MAX(column3) FROM table This gets the top value for each column but how can I get the second "max" value n times? ...

Pilcrow appears in all the column values after importing from CSV file - MYsql

Hello All, my CSV content looks like this 1234,123;123;123 5675,123;567;234;565 No Space is provided at the end of each row in CSV i.e. 1234,123;123;123(No space here) Imported this using the following command mysql> load data local infile 'E:\sample.csv' into table Test.Table1 fields terminated by ',' lines terminated by '\n' (Co...

how i cant select from mysql without duplication

my problem is too complex now i have files table I selected from it the files which added in last seven days. it returns many ids like 1,2,3,4,5 ok it's great. Now the problem: i have tutorial table every tutorial has some files of files table now i selected from files which last added from 7 days and make list ordered by files do...

Zend framework SQL select query construction (ORDER BY)

I have a database with VARCHAR column url. I would like to fetch rows so that the ones that have any url value have priority over other rows, but are ordered by date row (descending), so ORDER BY 'url' DESC, 'date' DESC wouldn't work as it would order them alphabetically first. Basically, it would look something like this: Table: ID ...

PHP/MySQL small-scale fuzzy search

I'm looking to implement fuzzy search for a small PHP/MySQL application. Specifically, I have a database with about 2400 records (records added at a rate of about 600 per year, so it's a small database). The three fields of interest are street address, last name and date. I want to be able to search by one of those fields, and essentiall...

mysql aggregate UDF (user defined function) in C

I need to write an aggregate extension function (implemented in C) for mySQL 5.x. I have scoured the documentation (including browsing sql/udf_example.c) but I do not find anything that is brief, to the point and shows me just what I need to do. This is the problem: I have a C struct (Foo) I have a C function that takes an array of t...

multi-thread access MySQL error

I have written a simple multi-threaded C program to access MySQL,it works fine except when i add usleep() or sleep() function in each thread function. i created two pthreads in the main method, int main(){ mysql_library_init(0,NULL,NULL); printf("Hello world!\n"); init_pool(&p,100); pthread_t producer; ...

MySQL query performance on two indexes + sorting

Hi, I'm implementing the following access policy: a User can access a Resource if he created it, belongs to the Resource's group members or if the resource is publicly available. Here is my DB structure (tables are MyISAM): User (1K-10K Users) id nickame … index user_name(id, nickname) Group (1K) id … Resource (10K-100K) ...

How can I delete an entry from a HABTM join table in rails?

Through many iterations of testing, I just noticed that my join table that represents a HABTM relationship between two models isn't removing entries when instances of these models get deleted. Do I need to do something special when removing an instance of a model that has HABTM relationships? ...

SQL repeat events by timer

I want that a column of my database, composed by float random numbers, change every x seconds determined by a timer. I read about Schedule Tasks Events but i can't work it. Please help ...

Doctrine (in symfony project) can not connect through socket

Hi guys ! I am trying to put a symfony project on a client server for production. The website worked fine on our company's server, but now i have this error : 500 | Internal Server Error | Doctrine_Connection_Exception PDO Connection Error: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql...

Problem with advanced distinct SQL query

Ok this one is realy tricky :D i have a this table bills_products: - bill_id - product_id - action - | 1 | 4 | add | | 1 | 5 | add | | 2 | 4 | remove | | 2 | 1 | add | | 3 | 4 | add | as you can see product with the id 4 was added at bill 1 then re...

Find conditions like 'NOT EXISTS'

Hi all... I have 2 tables in my db... Entita id int(11) descrizione varchar(50) ..... Publicobjects .... model varchar(50) the model I need (in this case 'Entita') model_id int(11) I would like to make a query like this: select entita.* from entita where NOT EXISTS (select * from publicobjects where publicobjects.model = 'Entita' and ...

Running a SQL query on my database behind the DMZ

Hi All, I am working on a web app that is hosted on a web server in a demilitarized zone (DMZ). I need to run MySQL queries on the database that is on its own server which is on the same local network as the web server, but not accessible via the internet. I can access the Web Server using putty, and the web server has MySQL installed....

How can I get rid of these comments in a MySQL dump?

I'm trying to create a simple structure only dump of my database. Using mysqldump gives me a result like: /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!...

mysqldump table names prefix

I have two mysql databases that have almost the same structure and representing the data of the same web app but one of them represents the current version and second one was made long time ago. How can I create the database with both dumps inside but with old_ prefix for tables from the first and new_ prefix for tables from the second ...