Jump to content

query problem


boon_chong

Recommended Posts

I'd like to query only the month of stockmovement.date, but when i use stockmovement.month(date) the error come out. Somebody please help me to figure out. Thx.

 

$query = "select distinct employee.itemNo,employee.itemDesc,employee.date,
employee.outlet,stockmovement.barcode,stockmovement.quantity,stockmovement.date 
from employee,stockmovement where 
employee.itemNo =stockmovement.barcode 
group by employee.itemNo";

 

Link to comment
https://forums.phpfreaks.com/topic/38720-query-problem/
Share on other sites

I'd like to query only the month of stockmovement.date, but when i use stockmovement.month(date) the error come out. Somebody please help me to figure out. thanks.

 

$query = "select distinct employee.itemNo,employee.itemDesc,employee.date,
employee.outlet,stockmovement.barcode,stockmovement.quantity,stockmovement.date 
from employee,stockmovement where 
employee.itemNo =stockmovement.barcode 
group by employee.itemNo";

 

 

I'll just clean it up to focus only on the SQL.

 

SELECT DISTINCT
       employee.itemNo, 
       employee.itemDesc,
       employee.date,
       employee.outlet,
       stockmovement.barcode,
       stockmovement.quantity,
       stockmovement.date
FROM employee, stockmovement
WHERE
       employee.itemNo = stockmovement.barcode,
GROUP BY employee.itemNo

 

Now, I'm not entirely sure what you want. Could you please rephrase? These are two of my interpretations:

 

1) To retreive the records where the stockmovement.date = certain month?

2) You want to convert stockmovement.date into something you can work with in your program logic (ie. via the date object)?

 

If #1, yea, as jcbarr said, the SQL forums'd find you plenty more answers.

Link to comment
https://forums.phpfreaks.com/topic/38720-query-problem/#findComment-186035
Share on other sites

Perhaps if you told us what the error was?

 

My guess is you want to do:

SELECT DISTINCT
       employee.itemNo, 
       employee.itemDesc,
       employee.date,
       employee.outlet,
       stockmovement.barcode,
       stockmovement.quantity,
       stockmovement.date
FROM employee, stockmovement
WHERE
       employee.itemNo = stockmovement.barcode AND
       MONTH(stockmovement.date) = $month_number
GROUP BY employee.itemNo

 

Where $month_number is an integer between 1 and 12, inclusive.

 

@8ball, You have an error in your MySQL query.  Check the manual for the correct syntax to use near "WHERE employee.itemNo = stockmovement.barcode, GROUP BY"  ;^]

Link to comment
https://forums.phpfreaks.com/topic/38720-query-problem/#findComment-186085
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.