Invalid Use of Group Function - php

Much of the query was put in variables, but for the purpose of this question I have included them in the query. Margin is the sum of all the alias queries above it ($margin).
I am getting the error:
SQLSTATE[HY000]: General error: 1111 Invalid use of group function in company-performance-control.php on line 117
Here is my query:
$margin = $invoicesOut.'-'.$costs.'+'.$creditsIn.'-'.$creditsOut ;
$result = $dbh->query("SELECT CONCAT(MONTH(invoices_out.date), '/', YEAR(invoices_out.date)) AS theDate,
SUM(COALESCE(
(SELECT SUM(invoices_out.net/rate)
FROM invoices_out, (SELECT jobRef, invoiceRef FROM invoices_out_reference GROUP BY invoiceRef) AS unique_references
WHERE unique_references.invoiceRef = invoices_out.id
AND unique_references.jobRef = jobs.id
),
0)) AS invoiced,
SUM((SELECT SUM((quantity*parts_trading.sellingNet)/currencies.rateVsPound)
FROM parts_trading, currencies
WHERE parts_trading.sellingCurrency = currencies.id
AND parts_trading.enquiryRef = enquiries.id
AND jobs.id NOT IN
(SELECT DISTINCT jobRef FROM invoices_out_reference)
)
+
COALESCE(
(SELECT SUM(enquiries_custom_fees.feeAmountNet/currencies.rateVsPound)
FROM enquiries_custom_fees, parts_trading, currencies
WHERE enquiries_custom_fees.enquiryRef = enquiries.id
AND enquiries_custom_fees.enquiryRef = parts_trading.enquiryRef
AND parts_trading.sellingCurrency = currencies.id
),
0
)) AS pending,
SUM(COALESCE(
(SELECT SUM(net)
FROM credit_notes_supplier, parts_trading_buying
WHERE credit_notes_supplier.partRef = parts_trading_buying.id
AND parts_trading_buying.enquiryRef = enquiries.id)
,0
)) AS creditsIn,
SUM(COALESCE(
(SELECT SUM(net)
FROM credit_notes_customer, parts_trading
WHERE credit_notes_customer.partRef = parts_trading.id
AND parts_trading.enquiryRef = enquiries.id)
,0
)) AS creditsOut,
SUM(((SELECT SUM(qty*(parts_trading_buying.buyingNet/currencies.rateVsPound))
FROM parts_trading_buying, currencies
WHERE parts_trading_buying.buyingCurrency = currencies.id
AND parts_trading_buying.enquiryRef = enquiries.id
)
+
COALESCE(
(SELECT SUM(parts_trading_buying_charges.feeAmountNet)
FROM parts_trading_buying_charges, parts_trading_buying
WHERE parts_trading_buying_charges.partRef = parts_trading_buying.id
AND parts_trading_buying.enquiryRef = enquiries.id
)
, 0))) AS costs,
SUM($margin) AS margin
FROM jobs, enquiries, invoices_out,
(SELECT jobRef, invoiceRef
FROM invoices_out_reference
GROUP BY invoiceRef
) AS unique_invoice_refs
WHERE enquiries.id = jobs.enquiryRef
AND unique_invoice_refs.invoiceRef = invoices_out.id
AND jobs.id = unique_invoice_refs.jobRef
AND jobs.stateRef != 1
AND jobs.stateRef != 5
GROUP BY YEAR(invoices_out.date), MONTH(invoices_out.date)") ;
I have narrowed it down to these:
SUM($creditsIn) AS creditsIn
SUM($creditsOut) AS creditsOut
Which are defined as:
$creditsIn = 'COALESCE(
(SELECT SUM(net)
FROM credit_notes_supplier, parts_trading_buying
WHERE credit_notes_supplier.partRef = parts_trading_buying.id
AND parts_trading_buying.enquiryRef = enquiries.id)
,0
)' ;
$creditsOut = 'COALESCE(
(SELECT SUM(net)
FROM credit_notes_customer, parts_trading
WHERE credit_notes_customer.partRef = parts_trading.id
AND parts_trading.enquiryRef = enquiries.id)
,0
)' ;

What a big query!
Troubleshoot this. Simply remove each subquery one at a time and determine which query is causing this.

Related

How to find the Total Records of outer query

This is my query
SELECT concat(sf.from_location, "-",sf.to_location) as from_to_city,
count( *) as seach_count,
(SELECT count(DISTINCT fb.origin) as no_of_book
FROM flight_booking_details as fb
WHERE fb.status="BOOKING_CONFIRMED" and
from_code=journey_from and
to_code=journey_to AND
DATE(fb.created_datetime) >="2018-07-01" AND
DATE(fb.created_datetime) <="2018-07-04" AND
fb.journey_from = 'BLR' AND
fb.journey_to = 'DEL' ) as booking_count
FROM search_flight_history sf
WHERE DATE(sf.created_datetime) >= '2018-07-01' AND
DATE(sf.created_datetime) <= '2018-07-04' AND
(sf.from_location = 'BLR' OR
sf.from_code = 'BLR') AND
(sf.to_location = 'DEL' OR
sf.to_code = 'DEL')
GROUP BY from_code,
to_code
Here I need to find the Total Records of this query.
Please any one help me to find this one
If really just need the count of rows returned by your query, you can try the following:
select count(*)
from
(
SELECT concat(sf.from_location, "-",sf.to_location) as from_to_city,
count( *) as seach_count,
(SELECT count(DISTINCT fb.origin) as no_of_book
FROM flight_booking_details as fb
WHERE fb.status="BOOKING_CONFIRMED" and
from_code=journey_from and
to_code=journey_to AND
DATE(fb.created_datetime) >="2018-07-01" AND
DATE(fb.created_datetime) <="2018-07-04" AND
fb.journey_from = 'BLR' AND
fb.journey_to = 'DEL' ) as booking_count
FROM search_flight_history sf
WHERE DATE(sf.created_datetime) >= '2018-07-01' AND
DATE(sf.created_datetime) <= '2018-07-04' AND
(sf.from_location = 'BLR' OR
sf.from_code = 'BLR') AND
(sf.to_location = 'DEL' OR
sf.to_code = 'DEL')
GROUP BY from_code,
to_code
) X;

my sql sub_query return_more than one row

Here is my mysql_query i want to add this query into my main query but the problem is when im add it to query it show sub query returns more than one row
(
SELECT date(trn_orderheader_approvedby.dtApprovedDate) AS CREATE_DATE
FROM trn_orderheader_approvedby
WHERE trn_orderheader_approvedby.intApproveLevelNo IN('-10')
)
AS Order_COMPLETED_DATE
SELECT
TB1.*, (
SELECT
SUM(TRNS.dblQty *- 1)
FROM
ware_stocktransactions_bulk AS TRNS
WHERE
TRNS.intOrderNo = TB1.`NO`
AND TRNS.intOrderYear = TB1.`YEAR`
AND TRNS.intSalesOrderId = TB1.intSalesOrderId
AND TRNS.intItemId = TB1.ITEM_ID
AND TRNS.intLocationId = TB1.LOCATION_ID
AND TRNS.strType IN ('ISSUE', 'RETSTORES')
) AS QTY,
(
SELECT
SUM(
TRNS.dblQty * TRNS.dblGRNRate * mst_financeexchangerate.dblBuying *- 1
)
FROM
ware_stocktransactions_bulk AS TRNS
LEFT JOIN mst_financeexchangerate ON mst_financeexchangerate.dtmDate = TRNS.dtGRNDate
AND mst_financeexchangerate.intCompanyId = TRNS.intCompanyId
AND mst_financeexchangerate.intCurrencyId = TRNS.intCurrencyId
WHERE
TRNS.intOrderNo = TB1.`NO`
AND TRNS.intOrderYear = TB1.`YEAR`
AND TRNS.intSalesOrderId = TB1.intSalesOrderId
AND TRNS.intItemId = TB1.ITEM_ID
AND TRNS.intLocationId = TB1.LOCATION_ID
AND TRNS.strType IN ('ISSUE', 'RETSTORES')
) AS AMOUNT,
(
SELECT
SUM(
costing_sample_header.INK_COST
)
FROM
costing_sample_header
WHERE
TB1.intSampleNo = costing_sample_header.SAMPLE_NO
AND TB1.intSampleYear = costing_sample_header.SAMPLE_YEAR
AND TB1.intRevisionNo = costing_sample_header.REVISION
AND TB1.strCombo = costing_sample_header.COMBO
AND TB1.strPrintName = costing_sample_header.PRINT
) AS INK_COST,
(
SELECT
SUM(
costing_sample_header.SPECIAL_RM_COST
)
FROM
costing_sample_header
WHERE
TB1.intSampleNo = costing_sample_header.SAMPLE_NO
AND TB1.intSampleYear = costing_sample_header.SAMPLE_YEAR
AND TB1.intRevisionNo = costing_sample_header.REVISION
AND TB1.strCombo = costing_sample_header.COMBO
AND TB1.strPrintName = costing_sample_header.PRINT
) AS RM_COST
FROM
(
SELECT DISTINCT
tempory_rm_moved_orders_summery2.`NO`,
tempory_rm_moved_orders_summery2.`YEAR`,
trn_orderdetails.intSalesOrderId,
trn_orderdetails.strSalesOrderNo,
trn_orderdetails.strGraphicNo,
trn_orderdetails.intSampleNo,
trn_orderdetails.intSampleYear,
trn_orderdetails.intRevisionNo,
trn_orderdetails.strCombo,
trn_orderdetails.strPrintName,
mst_part.strName AS part,
mst_locations.intId AS LOCATION_ID,
mst_locations.strName AS LOCATION,
trn_orderdetails.intQty,
mst_maincategory.strName AS MAIN_CATEGORY,
mst_subcategory.strName AS SUB_CATEGORY,
mst_item.intId AS ITEM_ID,
mst_item.strCode AS ITEM_CODE,
mst_item.strName AS ITEM_NAME,
mst_units.strCode AS UOM,
trn_po_prn_details_sales_order.PRODUCTION_QTY,
/* trn_po_prn_details_sales_order.CONS_PC,
trn_po_prn_details_sales_order.PRODUCTION_QTY,
trn_po_prn_details_sales_order.REQUIRED, sum( ifnull(
ware_stocktransactions_bulk.dblQty *- 1, 0 ) ) AS qty,*/
/*sum( ifnull( ware_stocktransactions_bulk.dblQty * ware_stocktransactions_bulk.dblGRNRate * mst_financeexchangerate.dblBuying *- 1, 0 ) ) AS amount, */
trn_orderdetails.dblPrice,
mst_customer.strName AS CUSTOMER_NAME,
mst_brand.strName AS BRAND_NAME,
trn_orderheader.intStatus,
IF (
trn_orderheader.intStatus = 1,
'Approved',
IF (
trn_orderheader.intStatus = 0,
'Rejected',
IF (
trn_orderheader.intStatus =- 10,
'Completed',
IF (
trn_orderheader.intStatus =- 2,
'Cancel',
IF (
trn_orderheader.intStatus =- 1,
'Revised',
'Pending'
)
)
)
)
) AS STATUS,
trn_orderdetails.dtDeliveryDate,
mst_technique_groups.TECHNIQUE_GROUP_NAME
FROM
ware_stocktransactions_bulk
INNER JOIN tempory_rm_moved_orders_summery2 ON ware_stocktransactions_bulk.intOrderNo = tempory_rm_moved_orders_summery2.`NO`
AND ware_stocktransactions_bulk.intOrderYear = tempory_rm_moved_orders_summery2.`YEAR`
AND date(
ware_stocktransactions_bulk.dtDate
) >= '2017-06-01'
INNER JOIN trn_orderdetails ON ware_stocktransactions_bulk.intOrderNo = trn_orderdetails.intOrderNo
AND ware_stocktransactions_bulk.intOrderYear = trn_orderdetails.intOrderYear
AND ware_stocktransactions_bulk.intSalesOrderId = trn_orderdetails.intSalesOrderId
INNER JOIN mst_part ON trn_orderdetails.intPart = mst_part.intId
INNER JOIN trn_orderheader ON trn_orderdetails.intOrderNo = trn_orderheader.intOrderNo
AND trn_orderdetails.intOrderYear = trn_orderheader.intOrderYear
INNER JOIN mst_item ON ware_stocktransactions_bulk.intItemId = mst_item.intId
INNER JOIN mst_maincategory ON mst_item.intMainCategory = mst_maincategory.intId
INNER JOIN mst_subcategory ON mst_item.intSubCategory = mst_subcategory.intId
INNER JOIN mst_units ON mst_item.intUOM = mst_units.intId
INNER JOIN mst_locations ON ware_stocktransactions_bulk.intLocationId = mst_locations.intId
INNER JOIN mst_customer ON trn_orderheader.intCustomer = mst_customer.intId
INNER JOIN trn_sampleinfomations ON trn_orderdetails.intSampleNo = trn_sampleinfomations.intSampleNo
AND trn_orderdetails.intSampleYear = trn_sampleinfomations.intSampleYear
AND trn_orderdetails.intRevisionNo = trn_sampleinfomations.intRevisionNo
INNER JOIN mst_brand ON trn_sampleinfomations.intBrand = mst_brand.intId
INNER JOIN mst_technique_groups ON trn_orderdetails.TECHNIQUE_GROUP_ID = mst_technique_groups.TECHNIQUE_GROUP_ID
LEFT JOIN trn_po_prn_details_sales_order ON ware_stocktransactions_bulk.intOrderYear = trn_po_prn_details_sales_order.ORDER_NO
AND ware_stocktransactions_bulk.intOrderYear = trn_po_prn_details_sales_order.ORDER_YEAR
AND ware_stocktransactions_bulk.intSalesOrderId = trn_po_prn_details_sales_order.SALES_ORDER
AND ware_stocktransactions_bulk.intItemId = trn_po_prn_details_sales_order.ITEM
WHERE
ware_stocktransactions_bulk.strType IN ('ISSUE', 'RETSTORES')
AND ware_stocktransactions_bulk.intOrderNo > 0
AND trn_po_prn_details_sales_order.ITEM IS NULL
/* GROUP BY ware_stocktransactions_bulk.intLocationId, ware_stocktransactions_bulk.intOrderNo, ware_stocktransactions_bulk.intOrderYear, ware_stocktransactions_bulk.intSalesOrderId, ware_stocktransactions_bulk.intItemId */
) AS TB1here
i found a solution like this
(
SELECT
trn_orderheader_approvedby.dtApprovedDate
FROM
trn_orderheader_approvedby
WHERE
trn_orderheader_approvedby.intApproveLevelNo = "-10"
AND trn_orderdetails.intOrderNo = trn_orderheader_approvedby.intOrderNo
AND trn_orderdetails.intOrderYear = trn_orderheader_approvedby.intYear
ORDER BY
trn_orderheader_approvedby.dtApprovedDate DESC
LIMIT 1
) AS COMPLETED_DATE

SQL Takes too much

For some reason my script takes too much time, that is why i had to add the ini_set('max_execution_time', 300); since 30 seconds being the default got me a fatal error.
I can't understand why this is happening, if i go directly into SSMS i get that query in 0 secs. what can be happening? i am running wamp with php 5.4.16 and the extension php_sqlsrv_54_ts
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
ini_set('max_execution_time', 300);
include "ChromePhp.php";
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'Cliente';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'DESC';
include "includes/db_config.php";
$conn = sqlsrv_connect(SV_NAME, $connectionInfo) OR die("Unable to connect to the database");
$sql =
"SELECT * FROM
(Select
Id
,Cliente
,Contrato
,Anexo
,SO
,NombreFlota
,(SELECT count(*) FROM LiveTest LEFT JOIN Producto ON Producto.Id=LiveTest.Producto_Id WHERE Producto.Order_Id=Orders.Id) as Hechas
,((SELECT count(*) FROM Producto WHERE Order_Id=Orders.Id) - (SELECT count(*) FROM LiveTest LEFT JOIN Producto ON Producto.Id=LiveTest.Producto_Id WHERE Producto.Order_Id=Orders.Id and RMA is null )) as Pendientes
,(SELECT count(*) FROM Producto WHERE Order_Id=Orders.Id ) as Total
FROM
Orders
WHERE
Orders.FechaPick is not null) as A
WHERE Total - Pendientes >0
ORDER BY $sort $order";
ChromePHP::log($sql);
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$result = array();
$res = sqlsrv_query($conn, $sql, $params, $options);
while($row = sqlsrv_fetch_object($res))
{
array_push($result, $row);
}
ChromePHP::log($result);
echo json_encode($result);
?>
try to modify your query like this:
Note : you do 'where f0b.Order_Id=f1.Id' then your left ouer join is cancelled because you test a value (that's why i have replaced by inner join), if you want null value too, you must do it : 'where f0b.Order_Id=f1.Id or f0b.Order_Id is null'
Select
Id
,Cliente
,Contrato
,Anexo
,SO
,NombreFlota
,isnull(f3.NbProdLive, 0) as Hechas
,isnull(f2.NbProd, 0) - isnull(f3.NbProdLiveRMANull, 0) as Pendientes
,isnull(f2.NbProd, 0) as Total
FROM
Orders f1
outer apply
(
select count(*) NbProd from Producto f0
where f0.Order_Id=f1.Id
) f2
outer apply
(
select count(*) NbProdLive, sum(case when RMA is null then 1 else 0 end) NbProdLiveRMANull
from LiveTest f0 INNER JOIN Producto f0b ON f0b.Id=f0.Producto_Id
where f0b.Order_Id=f1.Id
) f3
WHERE f1.FechaPick is not null and (isnull(f2.NbProd, 0) - (isnull(f2.NbProd, 0) - isnull(f3.NbProdLiveRMANull, 0))) >0
ORDER BY $sort $order

how to combine two queries to produce one result in codigniter

this is my query working fine
$offset = ($this->uri->segment(4))?$this->uri->segment(4):0;
$limit =10;
i donn't use $user_id becoz this function uses pagination
$q = "select distinct attandence.user_id ,monthname(date), sum(is_absent) as absents,in_time,out_time , count(date) as working_days, leave_type , users.f_name ,leave_types.type ,leave_types.leave_type_id , users.l_name ,( select count(leave_type) from attandence where leave_type != 0 and user_id = 4 and month(date) = 10 ) as leave_count from attandence join users on (users.user_id = attandence.user_id) left join leave_types on(leave_types.leave_type_id = attandence.leave_type) where in_time != '' and out_time != '' ".$where_condition." GROUP BY attandence.user_id LIMIT ".$limit." OFFSET ". $offset;
$rows = $this->attandence_model->q($q);
$this->data['Details'] = $rows;
in view i just passed
<? foreach ($Details as $detail){ ?>
<? } ?>
Any help is going to be appreciated. :)
I have solution your query you can add sub query Sub query
See Example:
$q = "select distinct attandence.user_id ,monthname(date), sum(is_absent) as absents,in_time,out_time , count(date) as working_days, leave_type , users.f_name ,leave_types.type ,leave_types.leave_type_id , users.l_name, (select count(leave_type) from attandence where leave_type != 0 and user_id = 15 and month(date) = 10) as leave_count from attandence join users on (users.user_id = attandence.user_id) left join leave_types on(leave_types.leave_type_id = attandence.leave_type) where in_time != '' and out_time != '' ".$where_condition." GROUP BY attandence.user_id LIMIT ".$limit." OFFSET ". $offset;

How Can I use Alias in Where

This is my code but it's not working:
$select = $db->select()
->from(array('p' => 'products'), 'p.product_id')
->columns(array('x' => new Zend_Db_Expr('(SELECT...)'
)))
->where('x = ?', 'value');
// Alternatively use columns('p.product_name')
How can I retrieve x and compere it in where clause?
This is the actual query:
SELECT `abstract_submission`.*,
(SELECT GROUP_CONCAT(CONCAT(user.firstName, " ", user.lastName) SEPARATOR ",")
FROM mamba_event.abstract_submission_reviewer reviewer INNER JOIN
mamba_account.account_user user ON user.id = reviewer.userId
WHERE reviewer.submissionId = mamba_event.abstract_submission.id AND
user.isEnabled = 1)
AS `reviewers`,
(SELECT GROUP_CONCAT(CONCAT(author.firstName, " ", author.lastName) SEPARATOR ",")
FROM mamba_event.abstract_author author INNER JOIN
mamba_event.abstract_submission_author map ON author.id = map.authorId
WHERE map.submissionId = mamba_event.abstract_submission.id)
AS `allAuthors`,
(SELECT COUNT(`abstract_paper`.`id`) FROM `mamba_event`.`abstract_paper`
WHERE `abstract_paper`.`submissionId` = `abstract_submission`.`id`)
AS `numPapers`,
(SELECT `paperNumber` FROM `mamba_event`.`abstract_paper`
WHERE `abstract_paper`.`submissionId` = `abstract_submission`.`id` AND
`abstract_paper`.`currentStatus` = 3 LIMIT 1)
AS `acceptedPaperNumber`,
(SELECT IF ((COUNT(1) > 0), 'Paper has been uploaded','None') AS hasUploadedPaper
FROM `mamba_event`.`abstract_paper` paper
WHERE paper.submissionId = `mamba_event`.`abstract_submission`.`id`)
AS `hasUploadedPaper`,
(SELECT GROUP_CONCAT(CONCAT(user.firstName, " ", user.lastName) SEPARATOR ",")
FROM `mamba_event`.`abstract_submission_reviewer` reviewer INNER JOIN
`mamba_account`.`account_user` user ON user.id = reviewer.userId
WHERE reviewer.submissionId = `mamba_event`.`abstract_submission`.`id`
AND reviewer.hasConflictOfInterest = 1
AND user.isEnabled = 1)
AS `reviewersWithConflict`,
(SELECT AVG(`score`) FROM `mamba_event`.`abstract_submission_score`
WHERE `submissionId` = `abstract_submission`.`id`)
AS `averageScore`,
(SELECT AVG(`score`) FROM `mamba_event`.`abstract_paper_score`, `mamba_event`.`abstract_paper`
WHERE `abstract_paper_score`.`paperId` = `abstract_paper`.`id`
AND `abstract_paper`.`submissionId` = `abstract_submission`.`id`
AND (`abstract_paper`.`currentStatus` = 1
OR `abstract_paper`.`currentStatus` = 3))
AS `averagePaperScore`,
(SELECT AVG(`score`*`scoreWeight`) FROM `mamba_event`.`abstract_submission_score` INNER JOIN
`mamba_event`.`abstract_request_criteria` ON `criteriaId` = `abstract_request_criteria`.`id`
WHERE `submissionId` = `abstract_submission`.`id`)
AS `averageWeightedScore`,
(SELECT AVG(`score`*`scoreWeight`) FROM `mamba_event`.`abstract_paper_score` JOIN
`mamba_event`.`abstract_paper` INNER JOIN
`mamba_event`.`abstract_request_criteria` ON
`criteriaId` = `abstract_request_criteria`.`id`
WHERE `abstract_paper_score`.`paperId` = `abstract_paper`.`id`
AND `abstract_paper`.`submissionId` = `abstract_submission`.`id`
AND (`abstract_paper`.`currentStatus` = 1
OR `abstract_paper`.`currentStatus` = 3))
AS `averageWeightedPaperScore`, `author`.`email`
AS `authorEmail`, `author`.`salutation`
AS `authorTitle`, `author`.`firstName`
AS `authorFirstName`, `author`.`lastName`
AS `authorLastName`, `author`.`organisation`
AS `authorOrganisation`, `author`.`position`
AS `authorPosition`, `author`.`department`
AS `authorDepartment`, `author`.`phone`
AS `authorPhone`, `author`.`fax`
AS `authorFax`, `address`.`line1`
AS `addressLine1`, `address`.`line2`
AS `addressLine2`, `address`.`line3`
AS `addressLine3`, `address`.`line4`
AS `addressLine4`, `address`.`city`
AS `addressCity`, `address`.`stateCode`
AS `addressStateCode`, `address`.`countryCode`
AS `addressCountryCode`, `address`.`postalCode`
AS `addressPostalCode`, `author`.`biography`
AS `authorBiography`, `request`.`title`
AS `request`, `request`.`blindReview`, `request`.`hasCustomTypes`, `file`.`content_type`, `file`.`original_filename` AS `filename`, `author`.`speakerId`,
(SELECT GROUP_CONCAT(
CONCAT('',ifnull(author.firstName,'-'),' ',
ifnull(author.lastName,'-'),'
(',ifnull(author.organisation,'-'),',
',ifnull(author.authorCountryCode,'-'),')')
SEPARATOR ",")
FROM `mamba_event`.`abstract_author` author LEFT JOIN
`mamba_event`.`abstract_submission_author` sa
ON sa.authorId = author.id
WHERE sa.submissionId = `abstract_submission`.`id`)
AS `authorDetails`,
(SELECT GROUP_CONCAT(`field`.`fieldValue`)
FROM `mamba_abstract`.`author_field_value_varchar` `field`
WHERE `field`.`fieldId` = '2185'
AND `field`.`authorId` = `abstract_submission`.`presenterId`)
AS `field2185`,
(SELECT GROUP_CONCAT(`field`.`fieldValue`)
FROM `mamba_abstract`.`author_field_value_varchar` `field`
WHERE `field`.`fieldId` = '2335'
AND `field`.`fieldValue` = 'BSCS'
AND `field`.`authorId` = `abstract_submission`.`presenterId`)
AS `field2335`,
(SELECT GROUP_CONCAT(`field`.`fieldValue`)
FROM `mamba_abstract`.`author_field_value_varchar` `field`
WHERE `field`.`fieldId` = '2336'
AND `field`.`authorId` = `abstract_submission`.`presenterId`)
AS `field2336` FROM `mamba_event`.`abstract_submission`
INNER JOIN `mamba_event`.`abstract_request` AS `request` ON requestId = request.id
LEFT JOIN `mamba_account`.`account_file` AS `file` ON fileId = file.id
INNER JOIN `mamba_event`.`abstract_author` AS `author` ON `presenterId` = `author`.`id`
LEFT JOIN `mamba_general`.`address` ON `author`.`addressId` = `address`.`id` WHERE ((`abstract_submission`.`isEnabled` = '1') AND (`abstract_submission`.`eventId` = '1893')) AND (`field2335` LIKE "%BSCS%") ORDER BY `request` asc LIMIT 15
You could do it with HAVING, like Muhammad Zeeshan said.
$select = $db->select()
->from(array('p' => 'products'), 'p.product_id')
->columns(array('x' => new Zend_Db_Expr('(SELECT...)')))
->having('x = ?', 'value');

Categories