I am Retrieve Data From MySQL Database, where the condition is if the checking out data field is null then check the send field to that particular row
id | SSC | hhc | dip
1 | 50 | 50 | null
2 | 60 | null| 60
3 | 50 | 55 | null
condition is "hhc" and "dip" are not both null and they are not both fill up at one time
i realy don't know what to do i try
$users->where('student_masters.hhc','>=' ,60);
$users->where('student_masters.dip','>=' ,60);
i retrive all data but condition is if('student_masters.hhc' == null)
then check the other field means student_masters.dip
please help me what i do
->where(function ($q) {
$q->where('student_masters.hhc','!=' ,null);
$q->where('student_masters.dip','=' ,null);
})
->orWhere(function ($q) {
$q->where('student_masters.hhc','=' ,null);
$q->where('student_masters.dip','!=' ,null);
})
This may help you. though question is not clear to me.
If you just want to pull the value of either column and don't care which one it came from, you could use a MySQL case statement. That will allow you to use the value of dip if hhc is null.
$users->select( DB::raw("CASE WHEN hhc IS NULL THEN dip ELSE hhc END AS data_value") )->get();
Note that we're using a raw select statement here as there is no way to do this with pure query builder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.