从2个表中选择并按1排序

I have 2 tables.

First:

TABLE Articles
  ID  

Second:

TABLE Viewcount
  DATE        DATE  PK
  ARTICLE_ID  INT   PK  (MATCHES ID IN TABLE Articles)
  NUMVIEWS    INT

How do I select all IDs from table Articles and then order by NUMVIEWS (DESC) of Viewcount according to dates? I then need to append the IDs from Articles that were not found in viewcount to the End of the results in no particular order. I know it has to be some sort of Join but I can't figure it out..

try this

SELECT id from Articles a
LEFT JOIN Viewcount v
ON  a.id = v.article_id
AND v.date = 'some date here'
ORDER BY v.numviews ,v.date desc

This should work:

SELECT * FROM `Articles` `a`, `Viewcount` `v`
WHERE `v`.`ARTICLE_ID`=`a`.`ID`
ORDER BY `v`.`NUMVIEWS` DESC

Replace SELECT * by SELECT `a`.`ID` to get only the Article IDs.

A simple join will suffice, yes:

SELECT a.id FROm Articles a LEFT JOIN Viewcount v
ON v.article_id = a.id
ORDER BY v.numviews desc, v.date
SELECT ID from (Articles JOIN Viewcount on Articles.ID = Viewcount.ID) ORDER BY Viewcount.NUMVIEWS, Viewcount.date