mysql-query

PHP query single line from database

I'm having a problem echoing a single line from a sql query. I'm still pretty new at this but I can't figure it out at all. I have a page titled "listing.php?id=7" Inside the page is this script: <?php mysql_connect("localhost","user","pass"); mysql_select_db("table"); $query = "SELECT * FROM vehicles WHERE id='$id'"; $result = mys...

Simple query takes 15-30 seconds

The following query is pretty simple. It selects the last 20 records from a messages table for use in a paging scenario. The first time this query is run, it takes from 15 to 30 seconds. Subsequent runs take less than a second (I expect some caching is involved). I am trying to determine why the first time takes so long. Here's the quer...

Query causes mysql server to go away

We have an application that has been deployed to 50+ websites. Across these sites we have noticed a piece of strange behaviour, we have now tracked this to one specific query. Very occasionally, once or twice a day usually, one of our debugging scripts reports 2006 : MySQL server has gone away I know there are a number of reasons this...

How to change the storage engine type on MySQL?

I would like to use InnoDB as the storage engine on all my tables and databases. Is there a command I can run to change the type of my current tables to use InnoDB instead of MyISAM? Also, is there a way to set this as the default so I don't have to do this again? ...

What is wrong in my MYSQL Query?

SELECT ( SELECT SUM(IF(status = 'Active', 1, 0)) AS `univ_active`, SUM(IF(status = 'Inactive', 1, 0)) AS 'univ_inactive', Count(*) FROM online_university ) AS tot_university, ( SELECT SUM(IF(status = 'Active', 1,0)) AS `user_active`, SUM(IF(status = 'Inactive', 1,0)) AS 'user_inactive' Count(*)...

Complex MySQL query between two tables

Hi, I've a real complex query here, at least for me. Here's a table with car dates releases (where model_key = 320D): +------------+-----------+ | date_key | model_key | +------------+-----------+ | 2003-08-13 | 320D | | 2005-11-12 | 320D | | 2007-02-11 | 320D | +------------+----------+ Then I have a table with d...

Retrieve multiple records based on multiple AND WHERE conditions

I am currently struggling with a query that needs to retrieve multiple records from my table based on multiple WHERE clauses. Each WHERE clause contains two conditions. Table layout: +--------------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+----...

Mysql_fetch_assoc is losing fields after assigning it to a array variable.

I have a simple function that calls a select query and populates an array with the results: $result = mysql_query($query); for ($n=0; $n < mysql_num_rows($result); $n++) { $row = mysql_fetch_assoc($result); $output[$n] = $row; } return $output; My table has about 60+ fields and mysql_fetch_assoc returns all of them. However...

Is it possible to create mutiple MySQL queries within the same table?

Is it possible to make multiple queries at once within the same query? Here is an example of what I'm trying to do. We have the following table: | userid | price | stock | description | ---------------------------------------- 1 10.00 5 some text 2 25.00 2 some text 3 15.00 3 some ...

Is there a way to transfer info from one database into another database?

I was wondering today if it was possible to transfer data from one database to another with one query. Say I have two tables: CREATE TABLE `Table_One` ( `ID` int(11) NOT NULL auto_increment, `Type_ID` int(11) NOT NULL, `Title` varchar(255) NOT NULL, `Date` varchar(100) NOT NULL, `Address` varchar(100) NOT NULL, `Town` varch...

Help with MySQL Query

Hello. I have two tables in my database, and I would like to retreive information from both of them without having to do two queries. Basically, the user_ID(s) retreived from the tasks table needs to be used to get those respective user(s) names from the users table. This is what I have so far, but the query is returning false: SELEC...

How do I increase Relevance value in an advanced MySQL query?

I've got a MySQL query similar to the following: SELECT *, MATCH (`Description`) AGAINST ('+ipod +touch ' IN BOOLEAN MODE) * 8 + MATCH(`Description`) AGAINST ('ipod touch' IN BOOLEAN MODE) AS Relevance FROM products WHERE ( MATCH (`Description`) AGAINST ('+ipod +touch' IN BOOLEAN MODE) OR MATCH(`LongDescription`) AGAINST ('+ipod +touch'...

Sub-query Optimization Talk with an example case

Hello guys, I need advises and want to share my experience about Query Optimization. This week, I found myself stuck in an interesting dilemma. I'm a novice person in mySql (2 years theory, less than one practical) Environment : I have a table that contains articles with a column 'type', and another table article_version that contain a...

Query from to date with php in mysql

Hello. I have a date field in a mysql table formatted like this: Y-m-d. I want to export every post that has a date between $fromDate and all the way to $toDate I am sure its easy but now i am totaly blocked from ideas. I am using codeigniter if that helps. Best Regards Audun ...

how to create mysql query for this criteria?

Hi, I have to write an query something like this select * from table where title like '% select from tableb %' this select from tableb is a query and not a string ...

Does HIBERNATE support the limit statement in MySql??

I am working on a project which uses Java,MySql,Struts2 MVC and Hibernate. I tried using limit statement in hql query but its not working properly. Select t from table1 t where t.column1 = :someVal limit 0,5 EDIT: I am using this as a namedQuery and calling this namedQuery using JPA Template This works correctly in MySql but when I r...

How do I remove slashes during a select statement

Please I am new. I am performing an insert select and I want to remove the slashes in a particular field say field b at the select portion of the query. eg. insert into mytable(a,b,c) select a, stripslashes(b),c from mysecondtable; Please help. ...

Force "implied AND" instead of "implied OR" in mysql boolean match?

In mysql boolean match, if no operators are present, OR is implied. If you want AND, you need to add + to each keywords. So query "word1 word2" is equal to "word1 OR word2", "+word1 +word2" is equal to "word1 AND word2" I don't want users to have to enter + before each keyword, what are my options? Suggested option 1: Is there some...

Mysql change number in column

Here is an easy question for someone. When using mysql, how do you increase or decrease the number in a particular cell by a specified amount with a single query. For example i have a product table with 5 x product a. I sell 1 item and i want to update the field. I want to do it with one query, not get the number add to it and then updat...

How to get affected rows in previous MySQL operation?

mysql_affected_rows is to get number of affected rows in previous MySQL operation, but I want to get affected rows in previous MySQL operation. For example: update mytable set status=2 where column3="a_variable"; Before this operation, status of some rows is already 2, and I want to get affected rows in previous MySQL operation, you c...