mysql-query

single quotes in SQL Query

Hi Guys, Im writing a php script that is used to update a database but it is giving errors when i tries to run the query it returns an error along the lines of 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 'id=15"' at line 1 Where it says "To us...

number_format() with MySQL

hey i need a way to get a formated number from my column decimal(23,2) NOT NULL DEFAULT '0.00' in php i could use this function number_format('1111.00', 2, ',', '.'); it would return 1.111,00 (in Germany we use , to define decimal numbers) how would i do this in mysql? with string replaces? ...

How do I pull values between two datetimes at specific interval in MySQL?

I have an application that writes temperature values to a MySQL table every second, It consists of the temperature and a datetime field. I need to pull these values out of the table at specific intervals, every second, minute, hour etc. So for example I will need to pull out values between 2 datetime fields and show the temperature at ...

I need the metadata from a mysql resultset, is this possible?

I'd like to obtain the metadata from the results of a mysql query so I can put it into a datatable in c#. I primarily need the column name and the data type. Here's a simple example. show columns from ( select sum(subtotal) as subtotal , sum(tax1+tax2+tax3+tax4) as tax , sum(subtotal)+sum(tax1+tax2+tax3+tax4) as total from tbltrans...

Under what conditions do I need to single quote a variable in a Mysql statement in PHP?

Under what conditions do I need to single quote a variable in a Mysql statement in PHP? ...

Optimizing a strange MySQL Query

Hoping someone can help with this. I have a query that pulls data from a PHP application and turns it into a view for use in a Ruby on Rails application. The PHP app's table is an E-A-V style table, with the following business rules: Given fields: First Name, Last Name, Email Address, Phone Number and Mobile Phone Carrier: Each pro...

How to design a table for the following requirement?

Hi all, I have the following requirement. Parent child mapping table ID ParentID ChildID 1 1 2 2 1 3 3 2 4 3 2 5 3 4 6 Main Table ID ViewCount 1 3 2 4 3 4 4 5 5 6 The Paren...

How to optimize mysql full match

Hey guys, do you know some trick about how can I optimize more a full match search? The code that I'm trying to optimize: $do = $this->select() ->where('MATCH(`name`,`ort`) AGAINST( ? IN BOOLEAN MODE)', $theString) ->order('premium DESC'); The search should search for some companies...and let's say that in the field name ...

mysql query tuning

Hello, I have a query that I have made into a MYSQL view. This particular view is central to our application so we are looking at tuning it. There is a primary key on Map_Id,User_No,X,Y. I am pretty comfortable tuning SQL server queries but not totally sure about how MySql works in this aspect. Would it help to put an index on it tha...

MySQL row order for "SELECT * FROM table_name;"

Assume that the following query is issued to a MySQL database: SELECT * FROM table_name; Note that no ORDER BY clause is given. My question is: Does MySQL give any guarantees to which order the result set rows will be given? More specifically, can I assume that the rows will be returned in insertion order (that is the same order in ...

SQL Query to pull records from 2 tables related to each other - Table 2 depending upon Table 1

Hi all, I have 2 tables. Table 1 is 'articles' and Table 2 is 'article_categories'. When a user creates an article, it is stored into 'articles'. The user, while creating the article can select various categories under which this article can appear. Currently, an article can be selected to belong to anywhere from 10-25 categories(may be ...

searching integers using fulltext search in mysql

Iam using fulltext search in my php file using mysql.But its not giving any result for integers like "Timber Jane 10". My requirement is to get exact search, that is, if I search a full name it should give exact matches which contains those words and in the order of best match in descending order no matter if the searched phrase is a t...

find all the name using mysql query which start with the letter 'a'

Hi All, I want to find the data from table artists where name is start with letter a, b, c. 1.e. My o/p should contain Adam Alan Bob Ben Chris Cameron But not GlAin, doC, dolBie Regards, Salil Gaikwad ...

How to join MySQL tables?

I basically have two tables: A(id int, name varchar(10), info varchar(10)) B(id int, item varchar(10)) A 1 A Hello 2 B World 3 C Foo B 1 apple 1 orange 1 hammer 2 glass 2 cup Note that C doesn't have any items. I want to join the two tables to get this: 1 A Hello apple|orange|hammer 2 B World glass|cup 3 C Foo null I am familiar ...

How to create multiple MySQL counts / group by / subqueries?

I have a table in my database containing football results, the relevant columns being matchNumber (a number based on the date), Result (either "W", "D" or "L") goalsFor, goalsAg and manager. I have this query: SELECT COUNT(*) AS P, (SELECT COUNT(*) FROM match_results WHERE manager = 13 AND Result = "W") AS W, (SELECT COUNT(*) FROM ...

Mysql SELECT inside UPDATE

UPDATE forms SET pos = (SELECT MIN(pos)-1 FROM forms) WHERE id=$id This doesn't work, error message: **You can't specify target table 'form' for update in FROM clause** I hope it's clear: I want to get the minimal element-1 from the same table and assign it to pos ...

Convert mysql SQL to oracle SQL

Hi, Is there a Free tool to convert MySql-5.0 SQL to Oracle-10g SQL? thanx in advance,,, ...

PHP Inbox Function

I received some great help on my last question. Here is where I'm at: I'm on the very last step of building a threaded messaging system for a dating website project for school and want to highlight a with a different bg color when a message is new. This is the table structure: CREATE TABLE `messages` ( `id` bigint (20) NOT NULL A...

Help with Query to group rooms free between particular dates under their respective hotels

Hi Everyone... I am building an online hotel booking system.... Using php and mysql.... Users can search for and book hotels in a particular location .. The search criteria will be 1. City or country 2. Check - in and Check Out dates 3. Number of guests My sql schema is as follows.... Table : hotels hotel_id hotel_name ...

How to do a query (limit between 2 ages - stored as date)

Hi, I have a table where it stores the users. And i want a query to find the users which are between eg 25 years old and 31 years old. The age is stored at the mysql table as date (it stores the birthday). (eg: 1980-02-25 (yyyy-mm-dd)) How the query should be written in order to find each time the people who are between two given ages? ...