How can I create mailing labels from a selective SQL query?

I can create mailing labels that take SQL table fields and populate a labels template with their values via File -> New -> Templates. The problem is it uses all rows when I want to use a SQL WHERE clause to select only some rows.

Am I supposed to make the query in Base first then pass the data in somehow?

I think the way is create a View and use it for mailing list.

That’s currently what I’m doing and now I’m trying to restrict it to the first 30 rows. I know the labels template and mail merge are making queries somehow, and I’d be fine(prefer) using an API to program these things in directly instead of messing with GUI.

Ok, got it working with a view and I see the API documentation. All is well.