OpenCart DB query issue (syntax misunderstand) - php

OpenCart v1.5.3.1, Export plugin:
$query = "SELECT pd.*, cg.name FROM `".DB_PREFIX."product_discount` pd ";
$query .= "LEFT JOIN `".DB_PREFIX."customer_group` cg ON cg.customer_group_id=pd.customer_group_id ";
$query .= "ORDER BY pd.product_id, cg.name";
Can anybody explain, what pd and cg means here?
Meet similar sintax in other places, but not sure what it means and how to work with it...
Looks like it is some common thing, but I am quite new to work with data bases yet, please help :-(
This query generate error:
Notice: Error: Unknown column 'cg.name' in 'field list' Error No:
1054

pd is the alias name for table `product_discount`
cg is the alias name for table `customer_group`
Notice: Error: Unknown column 'cg.name' in 'field list' Error No: 1054
This would actually mean there is no field of name in the table customer_group

Related

Error Code: 1054 Unknown column 'opdrachten.OpdrachtID' in 'field list'

When I run this query I get an error message but I dont know what Im doing wrong.
SELECT deelnemers.StudentenID, voorkeur.VoorkeurID,
opdrachten.OpdrachtID, voorkeur.Voorkeur
FROM deelnemers
INNER JOIN voorkeur, opdrachten ON voorkeur.StudentenID=deelnemers.StudentenID
WHERE VoorkeurID=1
AND voorkeur.Voorkeur=opdrachten.OpdrachtID
This is query is inserted in an table. Using PHP but when I tried running the query with SQLyog but still the same problem. I also checked multiple times if the column exists and yes it does
SELECT deelnemers.StudentenID, voorkeur.VoorkeurID, opdrachten.OpdrachtID,
voorkeur.Voorkeur FROM deelnemers
INNER JOIN voorkeur ON voorkeur.StudentenID = deelnemers.StudentenID INNER JOIN
opdrachten
ON voorkeur.StudentenID = deelnemers.StudentenID
WHERE VoorkeurID=1 AND voorkeur.Voorkeur = opdrachten.OpdrachtID
This was the what I used and Now I got what I want

Unknown column 'A.VOLUME' in 'field list' WHEN UPDATE A COLUMN

Not sure if this is a php/mysql bug however whenever I try to update a Column through PHP I get the following error 'Unknown column 'tablename.columnname' in 'field list'... just to make sure I typed up different variations of UPDATE queries directly on Terminal to test the syntax and they work fine, when I do the same through PHP the same error message..
CURRENTLY I'm trying to run this following query.
$updateSTKLISTVol = "UPDATE STKLIST AS A INNER JOIN (SELECT SYMBOL, VOLUME FROM $tablename WHERE id ='1') AS B ON A.SYMBOL = B.SYMBOL SET A.VOLUME=B.VOLUME";
$result5 = mysqli_query($dbcon, $updateSTKLISTVol) or die(mysqli_error($dbcon));
the error return is...
"Unknown column 'A.VOLUME' in 'field list' "
I would appreciate any guidance, thank you in advance.

Laravel: Unknown column when using alias in DB::raw()

I'm running the following SQL in Laravel:
$sql = 'SELECT university.id, university.name, MAX(uni_score) AS score
FROM (SELECT uni_id, place AS uni_score FROM ranking) AS tmp
LEFT JOIN university ON university.id = tmp.uni_id
ORDER BY score';
$result = DB::select(DB::raw($sql));
However the code throws this error:
Column not found: 1054 Unknown column 'uni_score' in 'field list'.
uni_score is an alias for place field in ranking table. The query above works fine when ran directly in phpMyAdmin.
What am I doing wrong?
Try using the DB::statement($query); method.

Having trouble with sql LIKE

I have the following query:
SELECT * FROM `alerts` WHERE `title` LIKE `%template%`
This should return at least 3 results with titles that includes the word 'template' but I'm getting the following error: -
1054 - Unknown column '%template%' in 'where clause'
As far as I can tell its syntactically correct and calling the correct column names. What am I missing?
Use single quotes for the %template%:
SELECT * FROM `alerts` WHERE `title` LIKE '%template%'

Strange problem when using HAVING() and Doctrine_Pager

My program generates this DQL using echo $q->getDql(); reformated for easier reading:
SELECT o.*, t.*, COUNT(t.id) AS num_of_reservations
FROM Property o
LEFT JOIN o.Reservation t
WITH t.status=? AND
( (t.start_date<=? AND t.end_date>=?)
OR (t.start_date>=? AND t.start_date <= ?) )
GROUP BY o.id
HAVING num_of_reservations < o.nr_of_bookings
Using PHP unit tests, I get results as expected. However, when I send this Doctrine_Query to Doctrine_Pager, I get this error:
Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'p.nr_of_bookings' in 'having clause'
I tried all combinations like using having('COUNT(t.id)..... ) etc, different SELECT combos, all results picked by $q->execute() are good except when I send it to pager.
Can somebody help me with this? I even tried
FROM Property p
instead of
FROM Property o
no difference at all.

Categories