0

<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

asi siyah
  • 9
  • 3
  • 1
    What are you trying to do? Please can you share some sample data and expected output? – DhruvJoshi May 11 '22 at 14:15
  • 1
    What RDBMS are you using? Likely the solution will involve Window Functions to establish order for filtering to do your `limit 5` and that may be RDBMS dependent. – JNevill May 11 '22 at 14:16
  • my database mysql and , i dont want output that name, comment. – asi siyah May 12 '22 at 10:08
  • Asi what are is your expected table? what do you want the outcome to look like? – BenHeb May 13 '22 at 06:01
  • hi, totaly i want see 2 colum, for first table : name position (last 5 entry), second table name place (last 5 entry) .. and out come is comment (names) , data (position and place) . – asi siyah May 13 '22 at 07:36

1 Answers1

0

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

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
asi siyah
  • 9
  • 3