Getting last entries from two different tables




 Hi,


I need to get the last entries from two different tables in MSSQL. I can get the last entry for one table by usung the following.

SELECT *
FROM dbo.Shaft\_Scales

WHERE dbo.Shaft\_Scales.ID = (SELECT max(ID) from dbo.Shaft\_Scales ID)



The problem is adding another table.



Please help
You could try using the in line view like this:


Select table1.col1, table1.col2, table1…., table2.col1, table2.col2, table2….  

 from  

(SELECT *  

FROM dbo.Shaft\_Scales  

WHERE dbo.Shaft\_Scales.ID = (SELECT max(ID) from dbo.Shaft\_Scales ID) as table1,  

(SELECT *  

FROM OtherTable  

WHERE dbo.OtherTable.ID = (SELECT max(ID) from dbo.OtherTable ID) as table2


—————- another approach from meandyou 


This works on [at least some] SQL processors


SELECT T1.* , T2.*  

FROM table1 T1, table2 T2  

WHERE …


Do we have to discuss why not to use “SELECT * ” in your SQL?<pre>


Try this


SELECT * FROM T1 as a, T2 as b WHERE a.ID = (SELECT max(ID) from T1)  

and b.ID = (SELECT max(ID) from T2);</pre>
ok, in that case replace these two lines
 last = lastrow(destsh)
 shlast = lastrow(sh)

with
 last = destsh.range("a" & rows.count).end(xlup).row
 shlast = sh.range("a" & rows.count).end(xlup).row let table = base.gettable("table 1")

let record = await input.recordasync("record", table)

await table.updaterecordasync(record.id, {

"single select": null

}) Try this:  


```
UPDATE table1
SET
    table1.firstname = table2.firstname,
    table1.lastname = table2.lastname,
    table1.email = table2.email
FROM
    table1 JOIN table2
ON
    table1.userid=table2.userid
``` you might be able to use synchronize. if you have more than 2 tables, you will need to use it multiple times. You need to iterate over the resource...

 
```
while ($row = mysql_fetch_object($tariff_query)) {
    echo $row->somefield;
    echo $row->someotherfield;
}

```
 So you now get all the records not just the first one.

 BTW, if you want to use an object, why not use PDO or mysqli? mysql is dead - or as good as. You can provide an optional parameter to the scaffolding command to update only the table you target.



```
Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DirectoryNameOfYourModels -Tables employee -f

```

If you are using .net core cli then use.



```
dotnet ef dbcontext scaffold "Server=(localdb)\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o DirectoryNameOfYourModels -t employee -f

``` Hi Djhenry,
  

  
When you right-click a sheets tab, you can select all sheets. When you have done that, you can insert a row and enter all the information and all sheets wil contain that information.
  

  
Best regards,
  
Trowa hi, @ricky007 
create table bill\_stag
(
s\_categry varchar2(20),
s\_billnum varchar2(20)
);

insert into bill values('1111','5647859541785');
watch out! you're using two different table names there.
you don't care which m\_billnum\_seq gets assigned to which new row, do you? (you shouldn't.) in that case, you can simplify the cross join approach that cormaco suggested like this:
insert into bill\_mast (m\_bill\_seqnum, m\_billnum, channel) -- always name the columns
with  all\_channels  as
(
 select 'mob' as channel  from dual  union all
 select 'atm'      from dual
)
select  seq\_num.nextval
, s.s\_billnum
, c.channel
from     bill\_stag    s
cross join all\_channels c
;
you don't need order by, so you don't need the ord column and you don't need so an extra sub-query. 1) p(x) = 1/x2 + 1 if x ≤ 3 it is clear that x= 3 is included, so you have to use this function.2) loo k at table d, and compare the given information with the data written inside the table. g = findgroups(yourtable.name);
output = splitapply(@(varargin) {table(varargin{:}, 'variablenames', yourtable.properties.variablenames)}, yourtable, g);
this should give a cell array of tables.