开发者

data from two tables and one show

开发者 https://www.devze.com 2023-03-26 13:07 出处:网络
I have two similar table in database, for example: news1: id | title | body| 1| aaa| aaa | 2| ggg| bbb | 2| xxx| ccc |

I have two similar table in database, for example:

news1:

id | title | body|
1  | aaa   | aaa |
2  | ggg   | bbb |
2  | xxx   | ccc |

and news2:

id | title | body | p开发者_开发技巧hoto |
1  | BBB   | 111  | 111
2  | RRR   | 222  | 222
3  | EEE   | 333  | 333

how can i get data from two tables and show in template for example order by title?

title | body | photo
aaa   | aaa
BBB   | 111  | 111
EEE   | 333  | 333
ggg   | ggg
RRR   | 222  |222
xxx   | xxx

?


use Union

SELECT *
  FROM news1 n1
UNION ALL
SELECT *
  FROM news2 n2

UNION ALL will be faster, but won't remove duplicates if they exist. Use UNION if you want duplicates removed. Joining two similar tables in MySQL

0

精彩评论

暂无评论...
验证码 换一张
取 消