mysql-query

I am not able to create foreign key in mysql Error 150. Please help

i am trying to create a foreign key in my table. But when i executes my query it shows me error 150. Error Code : 1025 Error on create foreign key of '.\vts\#sql-6ec_1' to '.\vts\tblguardian' (errno: 150) (0 ms taken) My Queries are Query to create a foreign Key alter table `vts`.`tblguardian` add constraint `FK_tblguardian` FOREIG...

Help with SQL query (add 5% to users with conditions)

Hi everyone, I’m having some difficulties with a query which purpose is to give users with more than one thread (called CS) in current year a 5% point “raise”. My relational schema looks like this: Thread = (**threadid**, threadname, threadLocation) threadoffering = (threadid, season, year, user) user = (**name**, points) Then, wha...

what is the use of mysql_pconnect

mysql_pconnect as I read does not close when the mysql_query ceases.. in that case why do we use this command?? does that create any security issue?? ...

CakePHP - Paginate / Query: find lowest of multiple fields & order by it

I am using CakePHP for a price-comparison website. I have a table products with fields: id, pride_regular, price_action. I would like to combine the fields price_regular and price_action into a dynamic field: price. The lowest value of these two fields should be the value of the new price field. Also I want to order on it Ascending. S...

Need to get the mysql query to show the next row every day.

I've set up a query to return notes for every day. now only the first row (id=1) shows. I'd like visitors to the site to see the next row on the next day, and so forth. ...

PHP - Get value of input box, without a form?

Hello. Does anyone know how I can get the value of an input box, without having a form? I want a submit button, but instead of submitting a form, I want it to change data in a MySQL database. Something like this maybe? $img1="WHAT DO I PUT HERE?" $idx=1 $sql="INSERT INTO games SET img1='$img1' WHERE id=$idx"; $result=mysql_query($s...

MySql left join on several regs

Hi there! I have this table1 idproduct(PK) | date_to_go 1 2010-01-18 2 2010-02-01 3 2010-02-21 4 2010-02-03 and this other table2 that controls date_to_go updates id | idproduct(FK) | prev_date_to_go | date_to_go | update_date 1 1 2010-01-01 2010-01-05 ...

Searching phpbb's 'topic_title' via MYSQL php, but exact match doesn't work

$sql = sprintf( "SELECT topic_title FROM `phpbb_topics` WHERE `topic_title` LIKE '%%%s%%' LIMIT 20" , mysql_real_escape_string('match this title') ); Which I run this query in phpMyAdmin the results are: (correct) match this title match this title 002 But when I run...

How can I track the last location of a shipment effeciently using latest date of reporting?

I need to find the latest location of each cargo item in a consignment. We mostly do this by looking at the route selected for a consignment and then finding the latest (max) time entered against nodes of this route. For example if a route has 5 nodes and we have entered timings against first 3 nodes, then the latest timing (max time) wi...

multi word query in mysql

Hi there , in order to make things easier for users i want to add multiple keyword search to my site. so that in the input the user would do something like : " keyword1 keyword 2" ( similar to google for example. would i need to write a code that would parse that string and do queries based on that or is there something built in mysql th...

How to select DISTINCT rows without having the ORDER BY field selected

So I have two tables students (PK sID) and mentors (PK pID). This query SELECT s.pID FROM students s JOIN mentors m ON s.pID = m.pID WHERE m.tags LIKE '%a%' ORDER BY s.sID DESC; delivers this result pID ------------- 9 9 3 9 3 9 9 9 10 9 3 10 etc... I am trying to get a list of distinct mentor ID's with this ordering so I am looki...

regular expression or replace function in where clause of a mysql query.

Hi All, I write a mysql query select * from table where name like '%salil%' which works fine but it will no return records with name 'sal-il', 'sa@lil'. So i want a query something like below select * from table whereremove_special_character_from(name)like '%salil%' remove_special_character_from(name) is a mysql method or a regul...

Why does this MySQL Query hang?

SELECT * FROM tbl_order_head AS o INNER JOIN tbl_orders_log AS c ON o.PAYMENT_TRANSACTION_LOG_ID=c.TRANSACTION_ID WHERE o.VISUAL_ID = '77783'; tbl_order_head 67,000 (30 fields) records, tbl_orders_log 17000 (5 fields) records. I don't know if it would eventually return as I am running it on a live server and fear overloading. I am do...

Speed up multiple JDBC SQL querys?

I'm working on a shortest path a* algorithm in java with a mysql db. I'm executing the following SQL Query approx 300 times in the program to find route connections from a database of 10,000 bus connections. It takes approx 6-7 seconds to execute the query 300 times. Any suggestions on how I can speed this up or any ideas on a different ...

mysql error in php

i'm trying to run this php code which should display a quote from mysql, but can't figure out where is it going wrong. the result variable is null or empty. can someone help me out. thanks! <?php include 'config.php'; // 'text' is the name of your table that contains // the information you want to pull from $rowcount = mysql_query("sel...

MySql SELECT AS - Append all field names

I'd like to do something like this: SELECT table.id AS prefix_id, table.name AS prefix_name ... and have the prefix added dynamically to all field names rather than selecting them all manually (ie SELECT table.* AS prefix_* or something) Hopefully I've described that accurately. Any thoughts? Edit To be clear, the reason I'm askin...

Help needed to construct a SQL query

Need your help to get the list of suggested friends (who aren't friends of the current user but are friends of 2 or more of the current user's friends). The primary ordering should put people at the same school at the top, and the secondary ordering should put people with more common friends (that is, the number of people who are friends...

Getting value depedning on two boolean attrinutes.[Nested ifs]

I have two fields start_time end_time -> can be null Now, depending on this I needs to differentiate between three states Scheduled in future, Currently running Completed in past Since mysql IF operator can not be nested, (Or I cant find an easy way to nest them), I cant find how to get the three state status. ...

SQL Join to only the maximum row puzzle

Given the following example data: Users +--------------------------------------------------+ | ID | First Name | Last Name | Network Identifier | +--------------------------------------------------+ | 1 | Billy | O'Neal | bro4 | +----+------------+-----------+--------------------+ | 2 | John | Skeet |...

Querying huge words listed in a file against 3 million MySQL records

What is the best way to query each word present in a huge word-list against 3 million MySQL records? Number of words in word-list file is approximately 10,000. Iterating over each word works but consumes huge amount of time. Is there any better way to optimize ? ...