tags:

views:

77

answers:

5

Have 2 table

1st {id_city,name } 
2nd table {id_ctz,name,sname,age,id_city}

need selected full information (name(city),name,sname,age) people with same name accending by age?

Have tried:

select city.name,citizen.name,age 
from citizen,city where city.id_city = citizen.id_city and citizen.name = '%s' 
order by age asc 

input varible is name

+2  A: 

This is the best I could do with the (lack of) information given.

SELECT *
FROM 1st a
JOIN 2nd b ON a.id_city=b.id_city
WHERE a.name = 'same'
ORDER BY b.age ASC

Note: Don't actually use the * as your output columns. Use the actual names.

Joe Philllips
A: 
select c2.name AS CityName,
c1.name AS CitizenName,
c1.age  AS CitizenAge
from citizen as C1 
inner join city as C2 on C1.id_city = c2.id_city
where c1.name = 'frank' 
order by c1.age asc 
p.campbell
it will be output only rows where name is 'Frank' but i need all another after
alexandr
@alexandr: you stated that you wanted 'people with same name accending by age'. Perhaps can you **edit your question** to include sample data, and then the results that you'd expect from the query?
p.campbell
+1  A: 

I'm guessing that you want all rows to be returned, and you want people with some name first, sorted by age. Afterwards you want all other rows. This query will do that:

SELECT city.name, citizen.name, citizen.age 
FROM citizen
JOIN city ON city.id_city = citizen.id_city
ORDER BY citizen.name <> 'some_name', citizen.age
Mark Byers
It work Thanks Mark Byers !!!! i dont now about that ORDER BY citizen.name <> 'varible'Thanks again!
alexandr
Nice guess! I like lucky charms
Joe Philllips
A: 

Is what you're looking for really help with how to pass a parameter to a query? In that case, your problem is ='%s'. You need to remove the single quotes. In a TSQL stored procedure, it would be = @s instead. MySQL I'm not sure about (you've got both tags), and if you're using something other than stored procedures to do a parameterized query, it would depend on the data provider you're using.

joelt
A: 

Apparently it does not make a one query Thank you for helping to understand this)

all Thanks

alexandr