mysql-query

just cannot fetch all content into variables

This is my code, my problem is content of ParentId and Tags is always null. It's not supposed to be like this. I do not why it happens? Can somebody tell why? CREATE PROCEDURE appendtags() BEGIN DECLARE done INT; DECLARE postId_1,postId_2,parentId INT(11); DECLARE tags VARCHAR(128); DECLARE cur1 CURSOR FOR SELECT PostId,ParentId F...

How to merge two tables based on common column and sort the results by date

Hello friends, I have two mysql tables and i want to merge the results of these two tables based on the common column rev_id. The merged results should be sorted by the date of two tables. Please help me. CREATE TABLE `reply` ( `id` int(3) NOT NULL auto_increment, `name` varchar(25) NOT NULL default '', `member_id` varchar(45) N...

MySQL search for a number in VARCHAR field

Hi There, I have a field in my database that contain comma separated values these values are numbers, and I am trying to do a search and count the number of times that a number appears in that column throughout the column, $sql = "SELECT sector_id_csv, COUNT(sector_id_csv) as count FROM cv WHERE sector_id_csv LIKE '$sectorId'"; Thi...

Several Small, Specific, MySQL Query Cache Questions

I've look all over the web and in the questions asked here about MySQL caching and most of them seem very non-specific about a couple of questions that I have about performance and MySQL query caching. Specifically I want answers to these questions, assume for all questions that I have the query cache enabled and it is of type 2, or "DE...

mysql insert multiple rows, return rows that failed

When I try to insert (lets say) 30 rows in my table. For example INSERT INTO customers(cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country) VALUES( 'Pep E. LaPew', '100 Main Street', 'Los Angeles', 'CA', '90046', 'USA' ), ( 'M. Mart...

Need help with a SELECT statement

I express the relationship between records and searchtags that can be attached to records like so: TABLE RECORDS id name TABLE SEARCHTAGS id recordid name I want to be able to SELECT records based on the searchtags that they have. For example, I want to be able to SELECT all records that have searchtags: (1 OR 2 OR 5) AND (6 OR 7)...

VB.net (aspx) mysql connection

Hey all i am new to ASP.NET and VB.net code behind. I have a classic ASP page that connects to the mySQL server with the following code: Set oConnection = Server.CreateObject("ADODB.Connection") Set oRecordset = Server.CreateObject("ADODB.Recordset") oConnection.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=xxx.com; PORT=3306; ...

Complex query making site extremely slow

select SQL_CALC_FOUND_ROWS DISTINCT media.*, username from album as album, album_permission as permission, user as user, media as media , word_tag as word_tag, tag as tag where ((media.album_id = album.album_id and album.private = 'yes' and album.album_id = permission.album_id and (permission.email = '' or permission.user_id = '') ) o...

mySQL date range problem

Hey all i am in need of a little help with figuring out how to get a range of days for my select query. Here is the code i am trying out: select id, idNumber, theDateStart, theDateEnd from clients WHERE idNumber = '010203' AND theDateStart >= '2010-04-09' AND theDateEnd <= '2010-04-09'; This is what the data in the table looks li...

How to make MYSQL query results ORDER BY conditions order?

My query string is like: SELECT ... FROM maintable LEFT JOIN table1 on (maintable.id = table1.idx) LEFT JOIN table2 on (table1.idy = table2.idy) LEFT JOIN table3 on (table2.idz = table3.idz) WHERE (condition1 OR condition2 OR condition3) AND maintable.status = static //condition1 & condition2 & condition3 are kind of table3.idz = 101, ...

How to match multiple field in mySQL

Im trying to match forum_id with several different forum_id's, something like forum_id = 5,7,12,43,63,78 I currently have this code: SELECT topic_title, topic_id, forum_id FROM $MYSQL_TOPIC WHERE topic_title LIKE '%%%s%%' AND forum_id = 5 LIMIT 50 (using mysql_real_escape_string and sprintf) I tried: forum_id = 5 OR 7 foru...

MySQL Gurus: How to pull a complex grid of data from MySQL database with one query?

Hopefully this is less complex than I think. I have one table of companies, and another table of jobs, and a third table with that contains a single entry for each employee in each job from each company. NOTE: Some companies won't have employees in some jobs, and some companies will have more than one employee in some jobs. The company...

Help with SQL query (Calculate a ratio between two entitiess)

Hi, I’m going to calculate a ratio between two entities but are having some trouble with the query. The principal is the same to, say a forum, where you say: A user gets points for every new thread. Then, calculate the ratio of points for the number of threads. Example: User A has 300 points. User A has started 6 thread. The point rat...

update mysql db through form in php

I am getting this error, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' address='xxxxx', city='sssssssss', pincode='333333333', state='Assam', count' at line 1 Thanks in advance. http://dpaste.com/hold/181959/ ...

which one run faster in mysql

which one run faster in mysql: a query with multiple joins or that query with using nested select? ...

SQL query: Delete a entry which is not present in a join table?

Hi, I’m going to delete all users which has no subscription but I seem to run into problems each time I try to detect the users. My schemas look like this: Users = {userid, name} Subscriptionoffering = {userid, subscriptionname} Now, what I’m going to do is to delete all users in the user table there has a count of zero in the subscr...

Force 'Replace Into' to use a certain index

I have a MySQL (5.0) table with 3 rows which are considered a combined Unique Index: CREATE TABLE `test`.`table_a` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `field1` varchar(5) COLLATE latin1_swedish_ci NOT NULL DEFAULT '', `field2` varchar(5) COLLATE latin1_swedish_ci NOT NULL DEFAULT '', `field3` varchar(5) COLLATE latin1_swedis...

Intersect in mysql

Hello everyone I need to implement following query in mysql (select * from emovis_reporting where (id=3 and cut_name= '全プロセス' and cut_name='恐慌') ) intersect ( select * from emovis_reporting where (id=3) and ( cut_name='全プロセス' or cut_name='恐慌') ) I know that intersect is not in m Mysql. So I need alternate way. Please guide me.... ...

Insert / Select with different Values Possible in MYSQL?

I need to insert values in to the db. INSERT INTO tblname(f1,f2,f3) SELECT f1,f2,f3 FROM othertbl This would insert exactly the values f1,f2,f3 from othertbl. What i want to do is Inserting a different value for f2. How can i do that in MYSQL. I hope i could explain my problem clear. ...

Find difference between two dates in php or mysql

How to find the age between two date using php or mysql 2009-09-24 21:09:36 2010-03-04 13:24:58 Thanks ...