My main problem is i dont know how to say select 1 on this cond select 2 on that cond. So i made them both their own statement. Is there a way to combine them?
select 1 from FlagContent where user=? and rev = ?;
select 2 from ContentRevision r
join ContentRevision r2 on r.content开发者_如何学Go=r2.content
join FlagContent fc on fc.user=? and fc.rev = r2.id
where r.id=?;
Use UNION
to "merge" similar result sets.
SQL UNION allows you to combine two or more than two result set from multiple tables together.
However, there are some conditions to using it:
- The number of columns in each SELECT statement has to be the same
- The data type of the column in the column list of the SELECT statement must be the same or at least convertible.
select 1 from FlagContent where user=? and rev = ?;
UNION ALL
select 2 from ContentRevision r
join ContentRevision r2 on r.content=r2.content
join FlagContent fc on fc.user=? and fc.rev = r2.id
where r.id=?;
精彩评论