Jump to content

Recommended Posts

I'm using mySQL 4.1.21 php and dreamweaver 8

 

I have two tables, I need to get a recordset that has all the records from one table and one record from the other.

 

How do I query it so that I get the state_id and state_name from Table B for a individual customer_id and all the state_id's and state_names from Table A (Table A sorted on country ascending)

 

Table A Table B

 

state_id    int(10)             state_id    int(10)

state_name  varchar(50) state_name  varchar(50)

country    varchar(50) customer_id  int(10)

 

Example:

 

401  Hemshire (from Table B)

001  Alabama (the rest from Table A)

002  Alaska

003  Arkansas

Link to comment
https://forums.phpfreaks.com/topic/55269-solved-would-like-help-with-a-query/
Share on other sites

Thanks, that helps some...but I still need to have table A ordered by country and state_name.

 

I tried this and get an error...Unknown table 'states' in order clause

 

SELECT state_id,state_name FROM other_states WHERE customer_id=46 UNION SELECT state_id,state_name FROM states ORDER BY states.country, states.state_name

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.