0
votes

I am using Yii2 basic. I have a table called groupsavingdetails. In that table I have records for a specific group with Id 29 and from year 2017 and Months August, September, October, November and December. Also there are records for the same group for year 2018 January and March.

The situation is I want to update record whose year is 2017 and month is September. Now I want to get all the records greater than September 2017 record. Total 5 records should I get but only 3 records are fetched by the following query.

SELECT * FROM groupsavingdetails WHERE groupsavingdetails.GroupId=29 and Year>=2017 and Month>9

Below is the image of table contaning records. So I should get records from Id 47,48,49,51,52. How should I get it.

enter image description here

1
Try WHERE CONCAT(month,"-",year) >= "09 - 2017" AND GroupId = 29Insane Skull
No still all records are displayedQuestions
Removed space WHERE CONCAT(Month,"-",Year) >= "9-2017" AND GroupId = 29Insane Skull
No, now the september months record is displayedQuestions
your month column is INT and year is YEAR in DB Structure?Insane Skull

1 Answers

0
votes
SELECT * FROM groupsavingdetails WHERE 
groupsavingdetails.GroupId=29 
and ( Year > 2017 or (Year>=2017 and Month > 9) )

In This query

if year is greater than 2017 it will display

and year is 2017 and month is greater than 9 also display