Jump to content

[SOLVED] Would like help with a query


jim.davidson

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.