If you want language=1 if no language=2 exists for a specific optionName then you could also use a union.
select * from tbl_options t1
where languageid = 1
and not exists
(select * from tbl_options t2
where languageid <> 1
and t1.optionName = t2.optionName )
union
select * from tbl_options
where languageid = 2 ;
If you only need a specific option you add the optionName
select * from tbl_options t1
where languageid = 1
and not exists
(select * from tbl_options t2
where languageid <> 1
and t1.optionName = t2.optionName )
and optionName IN ('opt1', 'opt2')
union
select * from tbl_options
where languageid = 2
and optionName IN ('opt1', 'opt2');
I tested it and it seems to work:
create table tbl_options (optionID number, optionName varchar2(50), optionValue varchar2(50), languageId number);
insert into tbl_options values (1,'opt1','Language 1',1);
insert into tbl_options values (2,'opt1','Language 2',2);
insert into tbl_options values (3,'opt2','Language 1',1);
select * from tbl_options;
select * from tbl_options t1
where languageid = 1
and not exists
(select * from tbl_options t2
where languageid <> 1
and t1.optionName = t2.optionName )
union all
select * from tbl_options
where languageid = 2
above outputs to (I did not use mysql but should be the same):
Table created.
1 row created.
1 row created.
1 row created.
OPTIONID OPTIONNAME OPTIONVALUE LANGUAGEID
---------- ---------- ------------ ----------
1 opt1 Language 1 1
2 opt1 Language 2 2
3 opt2 Language 1 1
3 rows selected.
OPTIONID OPTIONNAME OPTIONVALUE LANGUAGEID
---------- ---------- ------------ ----------
3 opt2 Language 1 1
2 opt1 Language 2 2
2 rows selected.