'Searching for data using subqueries in mysql
i have 2 tables
Table A
columns - id1(number), id2(alpha-numeric), createdOn(date), modifiedOn(date)
example data - id1 1043568, dfd43585-hfj653, any date, any date
id1 10438, dfd485-hfj653, any date, any date
id1 14568, dfd43585-hfj653, any date, any date
Table B
columns - id3, isValid
ex: id3 - 1043568, isValid - 0
id3 - 13568, isValid - 0
i have a query which fetches data based on input
select a.id1 as id, b.isValid as validity
from A a
join B b on a.id1=b.id3
where a.id2 like '435';
output: id - 1043568, validity -0
what i want is the data where the a.id2 like 435 or a.id1 like 435 expected output:
id - 1043568, validity - 0; id - dfd43585-hfj653, any date
what i wrote is
select a.id1 as id, b.isValid as validity
from A a
join B b on a.id1=b.id3
where a.id2 like '435' or a.id1 like '435';
but the query i wrote is not working. expected output is it should search for id1 & id3 (common in 2 tables) and also just the id2 from first table. maybe i need a subquery?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
