Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to LIMIT more than one output? 1

Status
Not open for further replies.

basildon

Programmer
Oct 22, 2001
58
GB
I have a Business database with many countrys on.

If I want to extract any 200 companies in Germany (in the same table) I could use

SELECT * FROM table
WHERE (country LIKE 'GER%')
LIMIT 200 ;

If, however, I want to select 200 companies from Germany, 200 from Spain, and 200 from Italy, can this be done in a single query?

Thanks

 
Unfortunately, no. The LIMIT directive operates at the level of the entire query, not at the level of the WHERE directive.

You could insert into a HASH table the first 200 of each company in three separate queries, then select all from that new table.

Or another way to do it would be to change your table structure by adding a column which numbers each company within a country. (The first German company entered into the table would get a count of 1, the first Italian company also a 1, the second German company would get at 2, etc). Then you could use a WHERE clause like WHERE ((country like 'GER%' or country like 'ITA%' or country like 'SPA%') and count < 200).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top