Запрос

Discussion in 'PHP' started by kotkew, 1 Nov 2013.

  1. kotkew

    kotkew New Member

    Joined:
    10 Jan 2013
    Messages:
    21
    Likes Received:
    0
    Reputations:
    0
    Здравствуйте, уважаемые.
    Есть запрос вида:
    Code:
    SELECT * FROM `table` WHERE ((`from` = 1 AND `to` = 2) OR (`from` = 2 AND `to` = 1)) AND (`fromstore` = 1  OR `tostore` = 1)
    Подскажите, как сформировать запрос, чтобы, если `from` = 1 и`to` = 2, то второе условие было `fromstore` = 1, а если `from` = 2 и `to` = 1, то второе условие было `tostore` = 1.
    Заранее благодарю.
     
  2. 4upakabr0

    4upakabr0 Member

    Joined:
    14 May 2008
    Messages:
    124
    Likes Received:
    23
    Reputations:
    0
    Code:
    SELECT * 
    FROM `table`
    WHERE	(	
    			(`from` = 1 AND `to` = 2)
    			AND
    			`fromstore` = 1
    		) 
    		OR 
    		(	
    			(`from` = 2 AND `to` = 1)
    			AND
    			`tostore` = 1 			
    		)
    пробуй, если я верно понял что ты хочешь
     
  3. kotkew

    kotkew New Member

    Joined:
    10 Jan 2013
    Messages:
    21
    Likes Received:
    0
    Reputations:
    0
    Верно, спасибо