I know many the many people think i can use "join" to pull data from two table but that's not i want.
actually it is kind of question to me, is it possible to pull data like this way here i am explaning :-
i have two table
+-------------------------------------+ +-------------------------------------+
| Table 1 | | Table 2 |
+-------------------------------------+ +-------------------------------------+
|id |vid| name | about | rank | |id |vid| title | description | rank |
+-------------------------------------+ +-------------------------------------+
| 1 | a | dsa | Lorem ipsu | 0 | | 1 | b | aa | Lorem ipsu | 0 |
| 2 | a | asda | adipisicin | 0 | | 2 | b | ss | adipisicin | 0 |
| 3 | a | da | tempor inc | 0 | | 3 | b | dd | tempor inc | 0 |
| 4 | a | sad | dolore mag | 2 | | 4 | b | rr | dolore mag | 2 |
| 5 | a | fd | quis nostr | 1 | | 5 | b | ggf | quis nostr | 2 |
| 6 | a | rewr | ullamco la | 2 | | 6 | b | ffdd | ullamco la | 1 |
| 7 | a | ewrr | consequat. | 2 | | 7 | b | df | consequat. | 1 |
| 8 | a | dsa | reprehende | 1 | | 8 | b | ddf | reprehende | 1 |
| 9 | a | fffd | cillum dol | 1 | | 9 | b | dfd | cillum dol | 1 |
| 10| a | fsd | Excepteur | 1 | | 10| b | df | Excepteur | 2 |
+-------------------------------------+ | 11| b | dff | proident, | 2 |
| 12| b | trr | deserunt m | 2 |
+-------------------------------------+
i want to pull data from both table but not i another column using join like left or right join is there any way to pull data in a new row where i with sorting rank in desc or asc order if yes then help me.
here is the result which i want
+-----------------------------------------+
| Result Table |
+-----------------------------------------+
| id | vid | name | about |rank |
+-----------------------------------------+
| 4 | b | rr | dolore mag | 2 |
| 5 | b | ggf | quis nostr | 2 |
| 10 | b | df | Excepteur | 2 |
| 11 | b | dff | proident, | 2 |
| 12 | b | trr | deserunt m | 2 |
| 4 | a | sad | dolore mag | 2 |
| 6 | a | rewr | ullamco la | 2 |
| 7 | a | ewrr | consequat. | 2 |
| 6 | b | ffdd | ullamco la | 1 |
| 7 | b | df | consequat. | 1 |
| 8 | b | ddf | reprehende | 1 |
| 9 | b | dfd | cillum dol | 1 |
| 5 | a | fd | quis nostr | 1 |
| 8 | a | dsa | reprehende | 1 |
| 9 | a | fffd | cillum dol | 1 |
| 10 | a | fsd | Excepteur | 1 |
| 1 | b | aa | Lorem ipsu | 0 |
| 2 | b | ss | adipisicin | 0 |
| 3 | b | dd | tempor inc | 0 |
| 1 | a | dsa | Lorem ipsu | 0 |
| 2 | a | asda | adipisicin | 0 |
| 3 | a | da | tempor inc | 0 |
+-----------------------------------------+
Thanks in advance.
try this:
select * from table1
UNION
select * from table2
ORDER BY 5 DESC, 1
this pulls from both tables, and orders by column#5 descending, and column#1 ascending
try use union all
and order by rank
and vid
desc
:
SELECT id,vid,name,about,rank
FROM(select id,vid,name,about,rank
from table1
UNION ALL
select id,vid,title as name,description as about,rank
from table2) t
order by rank desc,vid desc
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.