Joining Columns in Mysql Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leewad
Forum Commoner
Posts: 91
Joined: Tue May 11, 2004 8:32 am

Joining Columns in Mysql Query

Post by leewad »

Hi

Does anyone know how I can query 2 fields in a mysql database as one?

for example there is 8 fields in a rental database and 2 of them are fields price_short, price_long this is where customers can add whether they offer longterm or short term rentals, so some may just add price in longterm and some in just shortterm.

How can I query both these fields at once and display which ever one has a value in it?

I have tried something like this but it dont work

Code: Select all

SELECT * FROM  $table  (SELECT price_short,price_long) AS price WHERE price =300
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Joining Columns in Mysql Query

Post by jaoudestudios »

You will need to use CASE.

Here is an example...http://www.forum.jaoudestudios.com/view ... ?f=13&t=12
Post Reply