Since you didn't specify a country, this is a US centric answer:
National Best Bid and Offer (NBBO) is a Securities Exchange Commission (SEC) regulation requiring brokers to trade at the best available (lowest) ask price and the best available (highest) bid price when buying and selling securities for customers.
Any buy order at a price less than NBBO goes on the order book as a limit order at a lower price. The same holds true for a seller whose price is above NBBO.
For limit orders, the queue is determined by price and time. The first order at a given price is the first one in line. Those placing orders at that price are further back in line based on when their order was received (time).
If you are looking to buy or sell at the current NBBO quote, your order will be filled immediately. The only limitation is if your limit order size exceeds the available size at NBBO. Then, you'll get a partial fill unless you placed an All Or None order (AON), in which case you'll get nothing. If you place a market order then you'll get a fill at different prices.