How to update a table that is queried in the query itself?

I'm trying to update a table through a query, the query itself is created using the results of queries to other tables (one of which is the table we are updating)... However, I keep getting an error when I try to execute the query... After some resea

How can I set 0 if a query returns a null value in MySQL?

I am not so into database and I have the following problem. I have a query like this: SELECT sum(intervento.IMP_IND_POS_AFF_MIN) FROM TID023_INTERVENTO intervento INNER JOIN TID018_ENTEBENEFICIARIO enteBeneficiario ON(enteBeneficiario.COD_ENT = inter

Using 'LIKE' with the result of an SQL subquery

The following query is working absolutely fine for me: SELECT * From Customers WHERE Customers.ContactName = (SELECT FirstName FROM Employees as E, orders as O WHERE <condition> LIMIT 1); However, if i use LIKE instead of = to compare with the resul

What is the problem with my SQL COUNT clause

use prime_minister_2013; SELECT ministry.pm_name as 'PM Name', ministry.min_begin as 'Commencement Date', ministry.party as 'Party', deputy_pm.deputy_name as 'Deputy Name', governor_general.GG_title as 'Governor General Title', governor_general.GG_na

Laravel 4 Query Builder - maximum group date

little query question, I have table: id | user_id | paper_update ------------------------------ 1 | 1 | 30-5-2011 2 | 2 | 30-5-2012 3 | 3 | 30-5-2012 4 | 1 | 30-5-2013 5 | 2 | 30-5-2013 6 | 3 | 30-5-2014 7 | 4 | 30-5-2014 8 | 5 | 30-5-2014 9 | 5 | 30

MYSQL Skip extracting a column after a query

I need to run queries in mysql and dislay the output in some way, however the queries are provided by a third party and I can't change them. An example would be: SELECT j.`First Name`, j.`Last Name`, c .* FROM PersonalInfo j INNER JOIN Evaluations c

MySQL PDO Check if the email exists

So I'm stumped on why the function I've made to check if an email already exists in my database doesn't work...maybe someone here can help me! No matter what I do, it returns false and I cannot figure out why. This function below is within a file nam

MySQL quit the attached query with conditions - timeout

I have 2 table types, 1) properties 2) booked dates. The query below should be selecting the properties which don't have the relevant booked dates in the availability table. SELECT prop.*, ( 3959 * acos( cos( radians(50.2375800) ) * cos( radians(prop

Symfony2 Delete Registration Entity

I am having an issue with Symfony2 when it comes to removing a record from a table. I have a table that stores the following: purchaseOrders, purchaseOrderItems, and warehouses Purchase Order Entity "purchaseOrders" id|name | ----------- 1 |Test

SQL syntax error. 0 and 1

Well as the title says, I have a problem with my Syntax. 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 '1', '1', '1', '1', '0', '1', '0', '0', '0', '0', '0', '0',

Why does not my mysql query in php return more than one line?

I am trying to return a list of users' first and last names in JSON format in PHP. My PHP looks something like: $_Query = ' SELECT Fname,Lname FROM users WHERE number = "'.$_REQUEST['number'].'" ;'; $SQLResult = mysql_query($_Query) or die(mysql

How to store Gujarati data in the mysql server?

I want to execute one functionality in which i have to upload an excel sheet having data in gujarati font and after uploading i have to store that data into mysql database. Now here i have to use two languages for displaying output - one is english a

Multiple WHERE in the MySQL statement is causing me problems

I'm using CodeIgniter's db class to create the query. The query ends up looking like this; SELECT `user_id`, `firstname`, `lastname`, `email`, `school_id`, `country_id` FROM (`users`) WHERE `user_id` != '1' AND `firstname` = 'thomas' OR `lastname` =

mysql inserting a single row except the key

| id | -> primary key, auto_increment | v1 | | v2 | I want to make sure that there are no duplicate (v1, v2) pairs on insert. Is it possible via an SQL statement? Currently I do a select first and if there 's no result I continue with the insert. I w

MySql: if the value exists UPDATE else INSERT

I have some code that looks like this. There is also an autoincrement field in the table that I must retain (it is used in other tables). I would like to simplify and optimize this code. $query ="SELECT * FROM models WHERE col1 = 'foo'"; $testRe

Batch update column in phpMyAdmin

I want to update a specific column for all rows in a table in phpMyAdmin. I use this: UPDATE jk_m1_users SET group = '2' WHERE group = '1' However I get this error message: #1064 - You have an error in your SQL syntax; check the manual that correspon

Messy auto-join Mysql SELECT

I need to return a list of product id's that are... Within a specific category (for example 'Clothing') Which have various attributes, such as 'Red' or 'Green' Which are themselves within attribute 'groups' such as 'Color' I'm getting stuck when I ne

MYSQL query statement for an empty field

My database contains data as per the sample below. I would like to select the red highlighted row. Tried this query but doesn't display the row that I wanted. Any help is very much appreciated. <?php mysql_connect("localhost", "xxxxx&quo

Can MySQL reliably restore backups containing views or not?

Environment: Ubuntu 11.10, MySQL 5.1.58 I have a small database with views. When I try to dump and restore, I get ERROR 1356 (HY000) at line 1693: View 'curation2.condition_reference_qrm_v' references invalid table(s) or column(s) or function(s) or d

zend db select table does not exist error

So I'm trying to execute this query: SELECT r.refID AS rID, avgrat FROM rcc r; with Zend_Db_Select So I have this code: $sql = new Zend_Db_Select($db); $sql->from(array("r" => "rcc"), array("rID" => "refID"

Authorization script based on PHP5 level?

Are there any PHP login scripts around that I can learn from? I want to have a control panel that shows different options to different users depending on level of privilege.Yes, there are thousands of PHP scripts around that you can read and learn fr

How to auto update the database without refreshing with ajax?

i'm new here. i just create a code which can read the data from mysql database. But when i add in new data inside databse, my php page cant updated own automatic. I want the page can updated automaticly withour press f5 button and refresh. Can anyone

Mysql4: SQL to select a record or zero

Table layout: CREATE TABLE t_order (id INT, custId INT, order DATE) I'm looking for a SQL command to select a maximum of one row per order (the customer who owns the order is identified by a field named custId). I want to select ONE of the customer's

Using a table to keep the last ID used in a Web farm

I use a table with one row to keep the last used ID (I have my reasons to not use auto_increment), my app should work in a server farm so I wonder how I can update the last inserted ID (ie. increment it) and select the new ID in one step to avoid pro

Writing a unit test framework to test SQL stored procedures

Today I had an idea of writing a unit testing framework for stored procedures in MySQL. The full idea is written on a recent post on my blog. In short it goes like this: I want to automate my procedure testing, I want to use a standardized way to tes