Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Condition inside SQL in keyword

Tags:

sql

php

mysql

Here is my query

$qry="select * from table where colnam in ($int1, $int2)";

colname values can be 1,4,3,2

For example

if $int1=2;

I want to select 1, 2 and 3

if $int1=3;

I want to select 2, 3 and 4

Is it possible?

like image 322
Sugumar Venkatesan Avatar asked Nov 29 '25 14:11

Sugumar Venkatesan


1 Answers

Re-write query as:

$qry="select * from table where colnam BETWEEN $int1-- AND $int1++ ";

No need of $int2 at all. Just assign the values 2 or 3 in $int1 only.

like image 103
Muhammad Muazzam Avatar answered Dec 01 '25 04:12

Muhammad Muazzam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!