mysql-query

Joining 2 mysql queries

I have two tables which I need to select all rows from where the userid is $userid then sort them. I tried to use join but I couldn't even really get started on how to get it right. Can anybody point me in the right direction as to how to make these into 1 query? $result1 = mysql_query("SELECT * FROM paypal_sub_info WHERE ...

advantages of UPDATE LOW_PRIORITY and INSERT DELAYED INTO

I was going through some code and noticed that UPDATE LOW_PRIORITY and DELAYED INTO used for inserting and updating database. what is is the use of this code?? why we need to use this?? any Ideas?? Do I need to use it in every insertion and updation for various tables in same database?? ...

CakePHP update field value based on other value in same row?

I have been trying to figure out how to do this and it seems that its not something that many people are trying to do in cakephp or I am just completely misunderstanding the documentation.. I am using the following query below to get a field value so I get a value where the "findbycreated" is 0... this part works fine $unregisteredemail...

SQL statement for a 13 character long timestamp

Hello. I have a closed source application which put a 13 character long timestamp in a MySQL database. One value is for example: 1277953190942 Now I have the problem, that I have to write a sql statement which will return me all results of a table which match a special day. So I have for example 01. July 2010 and I will get all rows...

Exploding a string and looping through an array in MySQL outside another language

I'm creating a MySQL UDF (User Defined Function) to capitalise the first letter of every word. This is what I have so far: drop function if exists upperfirst; create function upperfirst (s varchar(255)) returns varchar(255) deterministic return concat(ucase(mid(lower(s),1,1)),mid(lower(s),2)); This is working pretty well so ...

Storing text in database with tags

Can anyone please help me with this? I want to know how to store text in database with the tags. For example, if the text is bold, italics, underlined, justification, paragraphs, space etc., then even that must be retrieved and displayed in the textarea of the jsp page. Please help me out! ...

How do I integrate date check function in single mysql query??

this is my current function: $result = $db->sql_query("SELECT * FROM data1,data2,data3,data4 WHERE person='" .$name. "'"); $row = $db->sql_fetchrow($result); $day = $row['regtime']; $days = (strtotime(date("Y-m-d")) - strtotime($row['regtime'])) / (60 * 60 * 24); if($row > 0 && $days < 15){ $row = ['name']; $row = ['age']; //etc bu...

what is the difference between UNIQUE INDEX and UNIQUE KEY??

I have seen couple of sample tables one is with UNIQUE INDEX and other is with UNIQUE KEY. what is the difference between two?? or both are same? ...

MySQL: list of sum for several conditions in one SQL statement

Hello to all! I have a problem with a MySQL statement: select sum(x) as "sum", "01.06.2010" as "date" from ( select distinct a.id as ID, a.dur as x from b_c inner join c on b_c.c_id = c.id inner join a on c.id = a.c_id inner join a_au on a.id = a_aud.id inner join d on a_au.rev = d.rev where ...

MySQL: Problem with max() and group by - wrong values

Hello to all! I have a problem with a SQL statement: Using this select a.id as ID, a.dur as DUR, DATE(FROM_UNIXTIME(timestampCol)) as date, a_au.re as RE, a_au.stat as STAT from b_c inner join c on b_c.c_id = c.id inner join a on c.id = a.c_id inner join a_au on a.id = a_au.id inner join revi on a_au.rev = revi.rev where b_...

MySQL: Using the dates in a between condition for the results.

Hello to all! I have a SQL statement in which I do this ... group by date having date between '2010-07-01' and '2010-07-10'; The result looks like: sum(test) day -------------------- 20 2010-07-03 120 2010-07-07 33 2010-07-09 42 2010-07-10 So I have these results, but is it possible, that I can wr...

Background update via PHP??

I don't know if it is possible only with PHP but thought will ask here... I do have a PHP code which updates data every 15 days. my problem is when it updates the entire process taking more than 5 seconds so user must wait until the updates done. what I am looking is I want to do an background update while user is viewing the content. ...

how to implement "contains" function in Mysql4.x ?

i have a keywords table,and i want to check a String contains keyword or not. String str="aaabbbccc"; TableName:keywordTable field:id keyword ------------------- 1 ee 2 bbb 3 xx .. ------------------ i run this sql (in mysql 4.1): select * from `keywordTable` where contains(`keyword`,"aaabbbccc"); return a syntax error how to imp...

all combination output in mysql

I have three tables: table1, table2, table3. Table1 contains: Title1 desc LHR LONDON HEATHROW LGW LONDON GATWICK Table2 contains: Title2 desc2 W1 TESTW1 W2 TESTW2 Table3 contains: vehicle desc3 SALOON SALOON DESC VIP VIP DESC EXECUTIVE EXECUTIVE DESC I want to output all combinations like t...

Query for related products

I have detail page for products and i want to add a module of "related products". In the db table "products" i store a value called "tags" for each product, something like "tag1, tag2, tag3, tag4". Now i need to build a query that retrieve all products that match at least 2 of this tags, excluding the id of the main product displayed ...

Many-to-many SQL relation: how to retrieve all related entries in one query?

Hi Guys! I have the same tables as in this question: http://stackoverflow.com/questions/1202978/mysql-query-over-many-to-many-relationship. What I'm struggling with, though, is how to construct a query which would obtain a plant with all its attributes. I.e. if I want P1 I get P1 | A1 | A2 | A3 or P1 | A1, A2, A3 As opposed to P1 | ...

what is the best possible schema for the following condition?

I need some help in creating the best possible table schema for the following condition. There is a competition where people are allowed to signup in groups. Each group has a groupid, each user has a uid, each group has group specific data like group_question_id etc. A single user can be part of multiple groups. Each user can answer t...

Update multiple rows with different, optional values for different colums

This is basically an extension of Update multiple rows with one query?. I want to be able to update multiple columns of multiple rows at a time, but not necessarily to update every column of every row. Here is an example command I would like to be able to execute: UPDATE person SET name = CASE id WHEN 1 THEN 'Jim' WHEN 3 THEN ...

MySQL: SELECT if next row is not as what is expected

So I have a log table. Rows are basically like this: id function n init() n+1 check() n+2 done() ... repeat But there are problems when it's like this: id function n init() n+1 check() n+2 done() n+3 check() <-- should be init! n+4 done() How do I find rows that happen only in init->check->done->check->done contagious order? ...

How do I show progress message while updating in PHP??

What I am looking into is:- I do have a search page say index page. and the action file is search.php. when I fire a query search.php will start processing on what I searched. structure of search.php it uses $_GET function to retrieve query from index page. first it will search in MySQL database. IF yes then display the result from ...