mysql-query

How to get the sql queries when trigger was triggered, upto n levels?

Hi, I want to list down the queries executed before the 'AFTER UPDATE TRIGGER' triggered upto n levels. The listing will be done within the TRIGGER itself. The n can be 4 or less. Any pointer or if listing can be done by any other way will be helpful? I have to debug the frontend and backend if bug is there. --Edit-- Accually a cell ...

Mysql - Select words from specified text

Hello guys, I have a table contains 413,000 places name (Pris, London,...) is there a way (query) to select locations from specified text. for example: " Transport for London (TfL) is in talks with its American, Australian and European partners about issuing a single contactless card for Paris, New York". I want a query to get: * Lo...

Problem with an SQL statement

Hi everyone ! I'm having a problem with an SQL statement. I want to activate a "ON UPDATE CASCADE" behavior for a foreign key in a table with this statement : ALTER TABLE "DB"."RECORD" ADD CONSTRAINT "RECORD_PT_OUTIL_FK1" FOREIGN KEY ("CDE_PO") REFERENCES "DB"."PT_OUTIL" ("CDE_PO") ON UPDATE CASCADE ENABLE; But when i run the statem...

Some Serious SQL Query Optimization Needed (MySQL)

Here's my current query: SELECT IFNULL(sum(open_for), 0) total, count(IF(open_for > 0, 1, null)) wins, count(IF(open_for < 0, 1, null)) losses FROM `sport_points` WHERE (sportable_id = 1 and sportable_type = 'Team' and game_time > '2010-07-13 11:39:58 UTC' It basically returns this aggregated data: TEAM A open_for total: 2000 win...

MySQL time between days

I have an application storing the times a restaurant is open: My code to get the currently open restaurants. My SQL query (simplified) looks like SELECT * FROM `restaurants` r WHERE r.from <= NOW() AND r.to >= NOW(); The problem here is, there's an entry which rolls over -- it's for a restaurant open from 11 AM to 3 AM the ...

mySQL "friends in common" query

Im trying to get a set of "Friends-in-Common" via the friends table: And then I would like to select * from the users table WHERE userId is in the friends in common set. friends .id...dom...sub .1.....2.....1 .2.....1.....3 .3.....1.....4 .4.....1.....5 .5.....2.....4 .6.....2.....6 .7.....3.....2 .8.....3.....6 .9.....2.....3 use...

error in running query

where h.er = select ( p.er from tip p where p.os = 'Android' OR 'iOS' ) AND h.ssn = (select h2.ssn from persons h2 where h2.ssn like '213%'); I am performing this function in mysql. IT is not letting me to do it. An error is coming like check the manual the mysql version cooresponds to. I am using 5.1.5.1 MYsql ...

get duplicated value in records

i have some records in a table. some of them have duplicated value in a field. i want to extract these duplicated values with mysql commands. how can i do that? ...

mysql NULL value in where in CLAUSE

how to deal with NULL value in mysql where in CLAUSE i try like SELECT * FROM mytable WHERE field IN(1,2,3,NULL) it not working only work like : SELECT * FROM mytable WHERE field IN(1,2,3) OR field IS NULL how can i get it work in WHERE IN ? it is possible ? ...

multiple condition in join

how can i use two or more condition on join? i want to replace this query with join version of it: select * from t1,t2 where t1.a=t2.b and t1.c=t2.d and t1.e=t2.f how could it be? ...

MySQL Insert date log

I am trying to find out when something was added to a database I maintain but the script that adds the date was working. Is there a way to retrieve the date of the original INSERT command? ...

Split strings in mysql

Hi All, I want to create a stored procedure which will do matching of two tables. My requirement is to match two tables based on the columns user passes as an input. Syntax: CREATE PROCEDURE reconcile.matchTables(IN TAB1 VARCHAR(25), IN TAB1 VARCHAR(25), IN COLS1 VARCHAR(250) , IN COLS2 VARCHAR(250)) EX: matchTables('table1', 'table2...

MYSQL: Using GROUP BY with string literals

I have the following table with these columns: shortName, fullName, ChangelistCount Is there a way to group them by a string literal within their fullName? The fullname represents file directories, so I would like to display results for certain parent folders instead of the individual files. I tried something along the lines of: GRO...

Average between two columns in mysql that are date not timestamp

Alright so here it is. I need to figure out the average amount of days between two columns. Column 1 is recieved_date and column 2 is fix_date Just want to know how to take the two dates find the difference in days, do that for every row and pop out a number stating the average amount of days it takes to fix something. Tried to find i...

Correct way of processing user input strings in SQL and PHP ?

I have designed a comment system. This is what I am basically doing. $story=$_POST['story']; $story=mysql_real_escape_string($story); $query = "INSERT INTO `comment` VALUES('$story')"; Now the problem is when i store the comment all the " are replaced by \" and all the ' are replaced by \'. So when I display the comments back these \ ...

mysql unknown column...

Hi there I am using this query SELECT COUNT(DISTINCT to_number) AS errors FROM sent_txts WHERE msg_link_id = 0 AND msg_sent_datetime BETWEEN '2010-08-09 07:00:00' AND '2010-09-07 11:59:59' HAVING to_number IN(SELECT mobile FROM action_6_members WHERE mobile = to_number) However I am getting Unknown column 'tada_prod.sent_txts.t...

How to calculate voting points in a Q&A website using MySQL query

Hello all I am trying to execute the following query SELECT a.userid, COUNT(a.id) AS count_answers, SUM(v.yes_vote) as total_up_votes, SUM(v.all_vote - v.yes_vote) as total_down_votes, CAST(COUNT(a.id) + SUM(v.yes_vote) * 4 - SUM(v.all_vote) AS SIGNED) AS voting_points FROM (answers a) LEFT OUTER JOIN answers_vote_count v ON r.id = v.a...

How to debug Hibernate

Suppose I have a simple hibernate program. In this program having a hibernate query. How do I debug this query so that I can know which query elements have values and which do not. ...

mysql query returns the value in the first column for all the other columns.

Hi I made a query to a table below and when I tried to get the value in each column , it returns the same value from the first column for all the other columns. To elaborate In my database table I have the following: owner_id = 21 pet_id = 1 name = fluffy color = green type = dog sub_type = boxer location = LA however whenever I try ...

MySQL passing variable to dynamic query

hi everyone, sorry if this is a basic question! up till now i have been creating mysql queries in php and passing across variables within the sql call like this: $myparam = $_GET["id_tbl"]; mysql_select_db($database_camerich, $camerich); $query_rs_table = sprintf("SELECT * FROM table_tbl WHERE idimg_tbl = ".$myparam." ORDER BY order_t...