I have one mysql query but when i'm trying to work showing me that error
Unknown column 'ps_address.phone_mobile' in 'field list'
Mysql Query is
SELECT
ps_orders.id_customer,
ps_customer.firstname,
ps_customer.lastname,
ps_customer.email,
ps_orders.total_paid,
ps_orders.date_add,
ps_address.phone_mobile
FROM
ps_orders JOIN ps_customer on ps_orders.id_customer = ps_customer.id_customer
WHERE ps_address.id_customer=ps_orders.id_customer and
ps_orders.total_paid > 1
AND ps_orders.id_customer IN (
SELECT
ps_orders.id_customer
FROM
ps_orders
GROUP BY
ps_orders.id_customer
HAVING
COUNT(1) < 2
)
You need to specifiy the table you're selecting FROM. So if the column exists, here's the updated query (abbreviated):
SELECT
ps_orders.id_customer,
ps_customer.firstname,
ps_customer.lastname,
ps_customer.email,
ps_orders.total_paid,
ps_orders.date_add,
ps_address.phone_mobile
FROM
ps_address, ps_orders
JOIN
ps_customer on ps_orders.id_customer = ps_customer.id_customer
WHERE
ps_address.id_customer=ps_orders.id_customer AND
ps_orders.total_paid > 1 AND
ps_orders.id_customer IN (...)
This syntax error means, you do not have this column "phone_mobile" in this table "ps_address".
The column does simply not exist?
Your script has syntax error. Column name "1" does not really exists in
COUNT(1) < 2
must be: COUNT(column_name) < 2
or COUNT(*) <2
COUNT(ps_orders.id_customer) < 2
Related
I have try to display result only if content > 0
SELECT actors.*, (SELECT count(*) FROM `content_actors`
WHERE content_actors.actor = actors.record_id) AS getCount
FROM actors
If i try to add in query
WHERE getCount > 0
I will have error
Unknown column 'getCount' in 'where clause'
In MySQL, you can use a having clause:
SELECT actors.*,
(SELECT count(*) FROM `content_actors` WHERE content_actors.actor = actors.record_id) AS getCount
FROM actors
HAVING getCount > 0;
This is a MySQL extension.
Assuming actors.record_id is unique (presumably a primary key), this could be written as:
SELECT a.*, COUNT(*) as getCount
FROM actors a JOIN
content_actors ca
ON ca.actor = a.record_id
GROUP BY a.record_id; -- assumes this is unique/primary key
No filtering is needed, because the JOIN requires at least one match.
Error
SQL query: Documentation
SELECT status.id AS id, status.status
FROM STATUS
WHERE id
IN (
SELECT student.id, student.fname
FROM student,
STATUS WHERE student.id =14
)
ORDER BY status_id DESC
MySQL said: Documentation
#1241 - Operand should contain 1 column(s)
The SELECT inside the IN() should not select more than one column.
in the subuery "SELECT student.id, student.fname" you have to extract only one field
i want use a subquery in a main query like following:
SELECT distinct(cnt.crid),cu.companyName,m.*,cnt.*,m.submitDate as mSubmitDate
from tbl_mahmoleh m,tbl_customer cu,tbl_cntreserve cnt
where m.cuID=cu.cuID and m.mBLID=cnt.mBLID and m.cuID='12'
and (cnt.crID IN (SELECT DISTINCT(crID) FROM tbl_paymentcnt))
and (cnt.crID IN (SELECT pc.crID, SUM( amount ) AS PaySum
FROM tbl_paymentcnt pc GROUP BY pc.crID HAVING PaySum < '2000'))
ORDER BY inputDateD
but i faced by this error
Blockquote #1241 - Operand should contain 1 column(s)
i got it, the IN clause can't work with more than one field, i changed my Query to the following and my Problem was solved.
SELECT DISTINCT(cnt.crid),cu.companyName,m.*,cnt.*,m.submitDate AS mSubmitDate
FROM tbl_mahmoleh m,tbl_customer cu,tbl_cntreserve cnt
WHERE m.cuID=cu.cuID AND m.mBLID = cnt.mBLID AND m.cuID = '12'
AND (cnt.crID IN (SELECT DISTINCT(crID) FROM tbl_paymentcnt))
AND (cnt.crID IN (SELECT pc.crID FROM tbl_paymentcnt pc GROUP BY pc.crID HAVING SUM(amount) < '2500'))
ORDER BY inputDateD
I am using a PHP mySQL query. Struggling with a Joins.
mysql_query("SELECT * FROM electors WHERE telephone > 0")
Then I need it to select from a table called voting_intention with matching ID from the electors table of this query and get a column called pledge that is equal to 'C' OR 'D'.
How do we do this in 1 mySQL query.
SELECT * FROM electors e
JOIN voting_intention vi ON (e.id = vi.id)
WHERE e.telephone > 0 and
vi.pledge in {'C','D'};
Your possible SQL statement will be,
SELECT voting_intention.pledge
FROM electors, voting_intention
WHERE
electors.id =voting_intention.id
and electors.telephone > 0
and voting_intention.pledge in {'C','D'}
In the following query am trying to get one image per category
SELECT l.*
FROM (
SELECT id AS category_id,
COALESCE(
(
SELECT *
FROM images li
WHERE li.category_id = dlo.id
ORDER BY
li.save_status DESC, li.category_id DESC, li.id DESC
LIMIT 1
), 0) AS mid
FROM cats_imgs dlo where id='1'
) lo
JOIN images l
ON l.save_status = '3'
AND l.category_id >= lo.category_id
AND l.category_id <= lo.category_id
AND l.id >= lo.mid
but keep getting the following error :
#1241 - Operand should contain 1 column(s)
Any ideas ?
replace * with a single column for images li
I had a similar problem. Your 3rd level select statement (SELECT * FROM images li) needs to return a single value, since the 2nd level select statement (SELECT id AS category_id,COALESCE( ...) is expecting only one value in its place holder.
For my case, it worked. Here I also averaged the data from a second based table (SecondBasis) to the values in the one minute basis table (MinuteBasis):
SELECT MinuteBasis.time, MinuteBasis.avg_t, MinuteBasis.avg_p,MinuteBasis.avg_t2,
(SELECT avg(SecondBasis.m1)
FROM SecondBasis
WHERE SecondBasis.time BETWEEN MinuteBasis.time AND addtime (MinuteBasis.time,'0 0:00:59'))
(SELECT avg(SecondBasis.m2)
FROM SecondBasis
WHERE SecondBasis.time BETWEEN MinuteBasis.time AND addtime (MinutBasis.time,'0 0:00:59'))
FROM MinuteBasis
WHERE MinuteBasis.time BETWEEN '2012-05-02 8:30:00' AND '2012-05-02 8:44:59' ;