www.webdeveloper.com
Results 1 to 2 of 2

Thread: combine 4 queries into one

  1. #1
    Join Date
    Feb 2006
    Posts
    1

    combine 4 queries into one

    hi friends,

    it should be simple though but i dont know how to do it...

    i have the following 4 queries:

    select pk_id as touristplaces from city_tourist_places ctp where ctp.city_id=2

    select cti.pk_id as traininfo from city_train_info cti where cti.city_id=2

    select cfi.pk_id as flightinfo from city_flight_info cfi where cfi.city_id=2

    select restaurant_id as restaurant from city_restaurant cr where cr.city_id=2

    i want to write only one single query.

    im only checking if a record exist for the specific city_id in all the above queries, please note city_id is exist in all tables.

    im using mysql 4.1.12.

    regards
    sanjeev

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    use the union keyword.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles