mysql-query

basic performance comparison

Do you know which table srtucture is better : table user id INT pk autoincrement name VARCHAR(255) email VARCHAR(255) statut TINYINT(4) The statut can only hold 2 states : 1/2 OR table user id INT pk autoincrement name VARCHAR(255) email VARCHAR(255) statut VARCHAR(45) The statut can only hold 2 states : ac...

Want to show data in group using group by

I have a table where there is composite key of id and emp_no. I want to show record of all tids against one emp_no like this (not using any aggregate functions because no need to show any thing like that): emp_no tid tid tid emp_no2 tid tid tid Thanks in advance ...

HoW can I count the row number in the returned group of mysql query

How can I get the row number in the returned mysql query , (i.e) if my query is returning some 5 rows as a result for ex... I wan to know that is 1st,2nd, 3rd ...etc thaks in advance ...

How to select the matching details from table mysql query equal to current date

Hi.., I have read the topic Mysql query: retrieve current date query ., but my question is how can i select the row in a particular given time span. i.e if my date field is having the entry as 2010:10:27 10:30:00 then that row should be selected when the current time reaches 2010:10:27 10:00 and until the current time reaches the 2010...

In MySql is it possible to have tables locked with only SELECTs?

Is it possible that, using only query statements in my code (and not using select lock) I still get tables locked for some time because of the way MySQL does the processing? (for example, MySQL can lock while ordering the table, or something like that) Is this possible or selects just don't lock? ...

Why are two separate MySQL statements duplicating each other?

I've got a require file that I use to display random products. On the home page it gets used twice, once in the main content section and then again in the sidebar. The problem I'm having is the second require doesn't overwrite the first sql results, it adds to them? The results I'm actually getting for the 2nd set of results are the 1st...

Interval datatype in MySql

Does MySql has the Interval datatype as PostgreSQL (or like TimeSpan in .net) does? ...

inserting data into mysql using sql query

On click of a button in asp.net c# i defined the following method to insert the data into the database. Is my insert query correct for mysql??I am not able to insert the data into the database. browser also is not throwing any errors. Can anyone help me to sort out the problem in my code? protected void Button2_Click(object sender, E...

PHP / MySQL Error Querying Email Address

Hi, I've been trying to query an email address using the following statement, however after hours of trying to escape the string successfully I've accepted defeat. The query I am using is: SELECT id, email FROM user WHERE email = '$email' That gives me an error: MySQL Error: You have an error in your SQL syntax; check the manual ...

I need to finalize this MySQL multiple table JOIN

I have entires, equipments, brands, times and seasons. entries: id time equipment_1 equipment_2 equipments: id id_brand brands: id name times: id id_season seasons: id name My actual SQL query is: SELECT entries.*, times.id_season AS id_season FROM entries, seasons WHERE entries.time = times.id But in the final qu...

Cakephp Complex Relation Find

I have a little complex Database model on which i am not able to make a proper find user(id, name...) 1 Harsha 2 Jasmine modules (id, name ) 1 Users 2 Restaurants 3 Dishes restaurant (id, name.... ) 1 KFC 2 Pizza Hut dishes (id, name, restaurant_id .. ) 1 Cheese Pizza 2 items (id, module_id, item_id) 1 1 1 (refers to U...

[MySQL] Extremely slow UPDATE query

Hi everyone. I noticed that a script of mine became very slow, then I narrowed down to the problem: it was an Update query. The weird thing is that the SELECT query is very fast. The table has about 600,000 entries. And yes, id is UNIQUE PRIMARY KEY. Here are some examples: SELECT * FROM `tmp_pages_data` WHERE id = 19080 LIMIT 0 , 30 ...

MySql - Problems in a query construct

Dear all, I need your help....I'm working on a little Time Management Sytem for my compagny. I have several tables, including this two tables : Pointage Id_check | id_user | week | time | ……. Users Id_user | first_name | last_name | ……… I would like find a means to construct a report which give me all people who didn't check 5 day...

PHP - MySQL error "Error: Query was empty" when someone tries to sign up with a username that is already taken

Hi, I've got a signup/login system on my site, and I've made it so that if someone tries to sign up with a username that is already in use, it posts an error underneath the form. However, instead of posting the error message that I created, it returns a MySQL error "Error: Query was empty". Here is the code that I am trying to use to do...

mySQL Create Procedure error + general mysql help

Hi I'm very very new at MySQL and was wondering if anyone could help me out. I'm trying to build a procedure for my database and am using the following code. CREATE PROCEDURE `createuser`(username VARCHAR(100), password VARCHAR(100), email VARCHAR(100)) BEGIN DECLare returnValue int; IF EXISTS(SELECT 'True' FROM User_Table WHERE(User...

Adding Seconds to datetime in MySQL

I'm trying to add seconds to a date based on certain events that occur. Often times, if these events occur at the same time, too many seconds get added on. Here's how I am currently doing it in PHP and MySQL $time_add_on = 15 - $seconds_left; DATE_ADD(STR_TO_DATE(end_dt,'%Y-%m-%d %H:%i:%s'), INTERVAL '".$time_add_on."' SECOND What t...

Why does this query work inside a block but not inside custom Panel content?

Why does the following query work within a Drupal Block, but not when part of a "custom content" in a pane within a Panels Page? It gives an error saying to check the syntax of the query near "AND node.type in....". Also, if I put it in a Block then display that Block inside a Panels Page, it works just fine. So while I've got this worki...

Help on a probably nested sql-query

Hello, I'm dealing with sql and my sql is not as good as my ruby, so I hope you can help me out. I have da table that looks like this: messages: id INTEGER PRIMARY KEY AUTO_INCREMENT to VARCHAR(255) text text shown DATETIME For now my script generates this part depending on the number of online players. "to = 'STEAM_0:0:xxx' OR to =...

mysql & php: temporary/ virtual ids for query results?

Hi, I wonder if it is possible to assign temporary/ virtual IDs for a query result? For instance, I have this as my query, SELECT pg_id AS ID, pg_url AS URL, pg_title AS Title, pg_content_1 AS Content FROM root_pages ORDER BY pg_created DESC output: ID URL Title Content 53 a A xxx 40 b B xxx ...

can I combine these 2 simple queries into one query?

select count(distinct id) from svn where name='ant' and type='Bug' and select count(distinct id) from svn where name='ant' and type='Feature' Is it possible to combine them into a single query that might reduce the execution time compared to running them individually? Thanks for answering. ...