'sql two table select data with desc limit 5 ( or select data in two table last 5 entry)
<table id='simple_table' >
<tr>
<th>customers ---</th>
<th>visitors ---</th>
<th>not show only for comment-----</th>
</tr>
<tr>
<td>john</td>
<td>nevada</td>
<td>table 1 position</td>
</tr>
<tr>
<td>jack</td>
<td>texas</td>
<td>table 1 position</td>
</tr>
<tr>
<td>....</td>
<td>....</td>
<td>table 1 position</td>
</tr>
<tr>
<td>....</td>
<td>....</td>
<td>table 1 position</td>
</tr>
<tr>
<td>...</td>
<td>...</td>
<td>table 1 position</td>
</tr>
<tr>
<td>cherry</td>
<td>right</td>
<td>table 2 place</td>
</tr>
<tr>
<td>apple</td>
<td>up</td>
<td>table 2 place</td>
</tr>
<tr>
<td>....</td>
<td>...</td>
<td>table 2 place</td>
</tr>
<tr>
<td>row9 col 1</td>
<td>....</td>
<td>table 2 place</td>
</tr>
<tr>
<td>..</td>
<td>...</td>
<td>table 2 place</td>
</tr>
</table>
hello is there anyone help me? i have two table on same database i want select and list one query like that :
Table 1: visitors
select perid ,name, position
from Table1
order by perid desc
limit 5
Table 2: customers
select butid, name, place
Table 2
order by butid desc
limit 5
thanks advance
Solution 1:[1]
It works like this:
(SELECT a FROM t1 ORDER BY a desc LIMIT 5)
UNION
(SELECT b FROM t2 ORDER BY b desc LIMIT 5);
I got this from the following post: Combining UNION and LIMIT operations in MySQL query
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jeremy Caney |