skip to Main Content

sample code

SELECT b.title, i.barcode
 FROM biblio b
 JOIN items i 
    ON b.biblionumber= i.biblionumber
 Join biblioitems bi 
    ON i.biblionumber=bi.biblionumber
 where i.barcode IN (4088,6183,6191)

above SQL given results as below,

enter image description here

how do I get results in IN (4088,6183,6191) as entered order

2

Answers


  1. You can try below modified Query.

    SELECT b.title, i.barcode
    FROM biblio b
    JOIN items i ON b.biblionumber = i.biblionumber
    JOIN biblioitems bi ON i.biblionumber = bi.biblionumber
    WHERE i.barcode IN (4088, 6183, 6191)
    ORDER BY FIELD(i.barcode, 4088, 6183, 6191);
    

    Hope this helps!!

    Login or Signup to reply.
  2. You can use the ORDER BY with CASE statement :

    <You query>
    order by case i.barcode 
              when 4088 then 1
              when 6183 then 2
              when 6191 then 3 
          end
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search